From nobody Wed Dec 17 19:36:25 2025 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 381842206AC; Fri, 6 Dec 2024 19:22:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733512978; cv=none; b=iROsmvUnqI5J52AJSvfBeQsq2TxFTc6Sg10Y2COs9dOXL6Cl4WvfGZ6yIqLCLC+HgFfQEN/Wu2spzU7eJmPzXY659T2HGV+CeGsjsjYJ5mVp+zZx3nllNJczgVhGWf7RRN8oz0Ay54Qcg6U0Z4lw/jYOd8BbJa0wzDJib73O95w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733512978; c=relaxed/simple; bh=ebPrHFVB3LsRQR1YXL7aeovncI3L/MNGFI6QBNUFgeM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=DmQ22X2skgJ82riTXrjlPXwmsjNuN7yp3UnJWxoozHzASQUmZOh17DVgU/zuVnEtQ8id3jY0PqvdzBCrL6ssPMJZfSeK5ACSLtDXVm+nNHNhUGBlWvGbb/GgwF7aBoplHzMWmwVyPEjVHyNMDANJ3U6p3/BYiTiYwtSj2jx3djs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JjnODlLV; arc=none smtp.client-ip=209.85.215.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JjnODlLV" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-7fc88476a02so2274409a12.2; Fri, 06 Dec 2024 11:22:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733512976; x=1734117776; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8idulI7k7enDyu+lEvRXSqg2AbC0967lekgmFvYpzpM=; b=JjnODlLVITHWqj36+8ROrIB460vBd7Fo4P5setiABAsaxip2un80f0kniSNBRIICX7 Y39UQg45MWZ+19qjm2m+ukgDyfAhVMzRFEvF7U1hRrPMu2nilk0qmPD0nCfg5UsihfLz K5GUgsY+gxTfXWBKq9So6ktJEudIRpCSgbkOCP1m7HsSrPmtf+pX2b6IxIe6XnWXcOFY e9/ddsq/nosj4gZ6zEmHaAJa8OZOwE/MaBYUYTJemS2LNli6/jDFfBmEWa6192aD5UAK DWPkfdnAAGgzenAYWukZCeNqPadXa5hkpynZeW0qbg2dye/q9BKPxKYIvj25FvB8M78J QXow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733512976; x=1734117776; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8idulI7k7enDyu+lEvRXSqg2AbC0967lekgmFvYpzpM=; b=hc2nog2fpbRg5tuERSpwPfE7bw1IWzw9HaDjYF0IEwif0ANYiNey2qyjKykK9jMQa9 Urkfjggv5hfhm4ZhMcflTlx6gIA9fKTKM0JJNePjrPE5gi9ItMIbe65Ld6yY1Ju/XcCu AFjLbzgY7E/8E9HO+oPOstZqG7Ca5K8oRHmJCr227qcl9xH2yFr7RrhFzKbFm38M+IoP +N2cyr+0u8c9eAr8MGYOWwqPI0bzuQ9u0c9ugelIdj36SHT0kaiOtl+fcAGe/7t+eyo5 PPRf7hMbuEngEGW5ypRZjeQ7q33cQDQ8GifFrPDRQX9PlU7LdwWfizeBvFKucv7Amvgp U1mw== X-Forwarded-Encrypted: i=1; AJvYcCWBc5LCOtBR+yEaDH4d1NQxe23LWTym1mEm4wbq/V4vIrM1kQnzAeUzxpnaKMARrsxqQXAUZk16M2BzSPvYTzk=@vger.kernel.org, AJvYcCWjpuqYWIgEd0N1E9q+0KUfKf92ygmvc701sycaPXv4eR3Ty2MPkkPolrGECebH9xylWzmoFUfvLiXk1HA=@vger.kernel.org X-Gm-Message-State: AOJu0YxfkkxWEWJz66IvwMgz1cJTBvz2rg7D/gjYFnWRWlAZ3cd9QFva c7VtthVPGN9gmfAuSEW/1j5hBdY4c+V3qGpx8wTrWI9UP3xRzY9B X-Gm-Gg: ASbGncsJBYj8UJTvGslN4Gf0kDUm1Oqo8uok8D8HuntuaJP98o17pJku9A4YqwuH+w7 1BtEbZQmrf9ekPZBeHhmiA6xHX+bppb6iffTw7q2XjSuG7CWS+6MzsTkd/Ur+x914xLElrZv2me y9464C4kJCq8sUO/6DHcdkDN7Jn6yHMdFXKKoU2mJMW9el4WVH3Q5Z4Agi64CmOjOwuTACyt380 aVMAKZK9mqRz/NpttbHXW/jrLEAfhGDdbsnbtOH3t8WyRsMFFyO3wXG X-Google-Smtp-Source: AGHT+IGEr9Q8CrKLOtiAnkHNOdh/DQVamnfvqZIvJ8UXxKzuAsa66jz6m3vsvWKI0u/G9smaLiJZEw== X-Received: by 2002:a05:6a21:3284:b0:1db:f603:4f2a with SMTP id adf61e73a8af0-1e1870bca20mr5152489637.14.1733512975129; Fri, 06 Dec 2024 11:22:55 -0800 (PST) Received: from linuxsimoes.. ([177.21.143.14]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7fd156ee2b5sm3377712a12.36.2024.12.06.11.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 11:22:54 -0800 (PST) From: guilherme giacomo simoes To: ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu, walmeida@microsoft.com, fujita.tomonori@gmail.com, tahbertschinger@gmail.com Cc: guilherme giacomo simoes , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [PATCH] rust: macros: add authors Date: Fri, 6 Dec 2024 16:22:44 -0300 Message-Id: <20241206192244.443486-1-trintaeoitogc@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The module is only accepted to have a single author. If the module needs more than one author, you cannot define this in the module creating flow. Add another key in the module stream that accepts a string array with authors. Author and authors keys cannot coexist, so add a check that if the module authors addss these two keys, throw a panic! Signed-off-by: guilherme giacomo simoes --- rust/macros/module.rs | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/rust/macros/module.rs b/rust/macros/module.rs index 2587f41b0d39..a6965354824f 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -83,6 +83,12 @@ fn emit_only_loadable(&mut self, field: &str, content: &= str) { self.emit_base(field, content, false) } =20 + fn emit_arr_str(&mut self, field: &str, arr_content: &Vec) { + for content in arr_content { + self.emit(field, content); + } + } + fn emit(&mut self, field: &str, content: &str) { self.emit_only_builtin(field, content); self.emit_only_loadable(field, content); @@ -95,12 +101,30 @@ struct ModuleInfo { license: String, name: String, author: Option, + authors: Option>, description: Option, alias: Option>, firmware: Option>, } =20 impl ModuleInfo { + fn coexist(arr: &mut Vec, cannot_coexist: &[&str]) -> bool { + let mut found: bool =3D false; + + for cc in cannot_coexist { + + for key in &mut *arr { + if cc =3D=3D key { + if found { + return true; + } + found =3D true; + } + } + } + return false; + } + fn parse(it: &mut token_stream::IntoIter) -> Self { let mut info =3D ModuleInfo::default(); =20 @@ -108,6 +132,7 @@ fn parse(it: &mut token_stream::IntoIter) -> Self { "type", "name", "author", + "authors", "description", "license", "alias", @@ -136,6 +161,7 @@ fn parse(it: &mut token_stream::IntoIter) -> Self { "type" =3D> info.type_ =3D expect_ident(it), "name" =3D> info.name =3D expect_string_ascii(it), "author" =3D> info.author =3D Some(expect_string(it)), + "authors" =3D> info.authors =3D Some(expect_string_array(i= t)), "description" =3D> info.description =3D Some(expect_string= (it)), "license" =3D> info.license =3D expect_string_ascii(it), "alias" =3D> info.alias =3D Some(expect_string_array(it)), @@ -153,6 +179,16 @@ fn parse(it: &mut token_stream::IntoIter) -> Self { =20 expect_end(it); =20 + const CANNOT_COEXIST: &[&[&str]] =3D &[ + &["author", "authors"] + ]; + + for cannot_coexist in CANNOT_COEXIST { + if Self::coexist(&mut seen_keys, cannot_coexist) { + panic!("keys {:?} coexist", cannot_coexist); + } + } + for key in REQUIRED_KEYS { if !seen_keys.iter().any(|e| e =3D=3D key) { panic!("Missing required key \"{}\".", key); @@ -183,6 +219,9 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { let info =3D ModuleInfo::parse(&mut it); =20 let mut modinfo =3D ModInfoBuilder::new(info.name.as_ref()); + if let Some(authors) =3D info.authors { + modinfo.emit_arr_str("author", &authors); + } if let Some(author) =3D info.author { modinfo.emit("author", &author); } @@ -191,9 +230,7 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream { } modinfo.emit("license", &info.license); if let Some(aliases) =3D info.alias { - for alias in aliases { - modinfo.emit("alias", &alias); - } + modinfo.emit_arr_str("alias", &aliases); } if let Some(firmware) =3D info.firmware { for fw in firmware { --=20 2.34.1