From nobody Tue Dec 16 11:04:29 2025 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 CCF771F1521; Thu, 20 Feb 2025 16:20:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740068415; cv=none; b=acbJ12K9fg5ZNkry4heI8DGDzKuTDx7jd5fCH/pb+hhirzvObVT95CE9j6B0zIpLjTprW/ne2qVJDp0VtC+mrLg6y6/2UGEEm1mnUARKPPXN0vBN7GMEUVZQjiHBZH/aYX1nDmW9QEDZD2FW/O0Lldl1lvTvrS3lXyfajjZrUXc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740068415; c=relaxed/simple; bh=4cDqNmayQUdKr8uDiJ1UR81pYo0A4k0A2thyrxtwI9g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N6ygg9RyNYXFupVtKWc57Q3ja4Hp21BBK7kY895qCaPN6JAq1vgF09AjgrY2+SGGQYrJMSTep/Srfnns2i+Z/90WNweAA3BOsQEngeQRbzEhUoFtld0IQD4SDwtDWdhmbFtInkBbCcHshicSdERiqFmdFQwvXzwstXMN9Gueo+E= 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=bmtcvvJ+; arc=none smtp.client-ip=209.85.214.178 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="bmtcvvJ+" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-220ecbdb4c2so29680085ad.3; Thu, 20 Feb 2025 08:20:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740068413; x=1740673213; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=80RkjWb0QgyuebLouunjzNOxx/sMfImn9rNTeqSYLhE=; b=bmtcvvJ+hWjfu8oll+5gqA57xwBsKj6aUFqfreq4eVvs0D5FzEm00aZTPw8HM3Rm0L ouEZOBcR79HTD3QduvtSuON+q28lcQq5Eo7L9jQmeZdIAdDcxlmiAcMboDj1M6zPDVMz 8zYsqdmrsSp/E3fBjvgwIKvRQgTauFliMP1g4S1a2ASQv/qmqcfPeINJLY63UXdoHlc3 XjRJMh8y1445BZUUEn39ydzsumZWCUDXTm1TE+s+Xo6aK/Wojk3nKVVFWOXm+tdsUY9o +J1d5kk6ZcG8SW9DwVEfADagn5J9WYGx0VThH1+SgEQddD5icGluQ7JE8tDTN49jljI4 kChQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740068413; x=1740673213; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=80RkjWb0QgyuebLouunjzNOxx/sMfImn9rNTeqSYLhE=; b=BYzQUJiRFAsHyUK/NHkonyPGKAsRxYpbEAeAwbU/yJbp+J3zQ1C61IJMfvCGQ3eFwM ZbC+ec4B7es2C8kgCUzQ9burpGPhUcKWqGxmqQKh9QW0hd1YyIscL3WGu3ffkZ7W6IcH lFy3GjAXzKasq/ymHYigYybWDpYOVvVeN4JNybs9vn1Z+GqNqaPV1gngUlYrthi2Zls8 E/ngBnjQ+/ioy63ZlqJwzRp0MpfweewLZenvfNjUnHvhyB4WWe6d8KLLhDrDlwK5OH/G /qVWWTomxncGA/dLYrz/6wRcgXYzRQbCQbLhV7eJfAEDY5JBaIaNcD+GLpleBDMkJUiL pzEQ== X-Forwarded-Encrypted: i=1; AJvYcCXMa6j/KXrCDIW31QfY1+c/jbwNLjZGeiyn+iG7tN3hJCjTUyMRn1amxABDcB05vkBg5ntarlgiUykSA/ZqKiI=@vger.kernel.org, AJvYcCXN2NTeZmDRxswStWA7Ue9pMqxD0hmNJ3HEz/uUpAyssnDMv7E/nm66VJKaPhZR6Oo3VmaQyvlky9Y7Qh0=@vger.kernel.org X-Gm-Message-State: AOJu0YzB+QK545AExwHMsFMdtId1WismUG9BWNKrE+gEzVTaz1/N9Qdv 4EDCcyu2OXBn8/DmpSXiuH4bCdKrQwBCSHOk1J4dFHAOKxod2eBq X-Gm-Gg: ASbGncvOZig+cIv5pbpy1dOLMuLZnOeR9KsM88IvmRoxOWK4rbuXc5XBEBfR0kwDHHM FQuEYwS4fM8D5D1WmNkePAKPZKi3OVG3toX57sIGBJoNotVwfUhkBdzVHM5cXjJW1PBeW58Q4AP +juwUSkpmOcY4ELBYMwK7flyvYpXtUrOb8y4DTAe6Ab8EpSLJclBOv232g5KRm7hRZ6WIBXgVXo qTDfuGKMzFZJ+15OSoP0Ch49113frk94dOAM9nxDoAwVaJ9/uDOtT7OfR4GfuuNw4Xu2pgUPQ1s 2+sR1Lzvq7+XwdWD/keeaB0= X-Google-Smtp-Source: AGHT+IEewydMRUrml5TxMB84gBMP31ciuqEiIjAHev3XWeYiny1ydqjoRXGZpN8NXpLaZ3S5J7bhUQ== X-Received: by 2002:a17:902:d58b:b0:21f:dbb:20a6 with SMTP id d9443c01a7336-221040ab935mr398205165ad.33.1740068412956; Thu, 20 Feb 2025 08:20:12 -0800 (PST) Received: from linuxsimoes.. ([177.21.141.136]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d7a540aasm120910545ad.245.2025.02.20.08.20.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2025 08:20:12 -0800 (PST) From: Guilherme Giacomo Simoes To: a.hindborg@kernel.org, alex.gaynor@gmail.com, aliceryhl@google.com, apw@canonical.com, arnd@arndb.de, aswinunni01@gmail.com, axboe@kernel.dk, benno.lossin@proton.me, bhelgaas@google.com, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, dakr@kernel.org, dwaipayanray1@gmail.com, ethan.twardy@gmail.com, fujita.tomonori@gmail.com, gary@garyguo.net, gregkh@linuxfoundation.org, joe@perches.com, lukas.bulwahn@gmail.com, ojeda@kernel.org, pbonzini@redhat.com, tmgross@umich.edu, walmeida@microsoft.com Cc: trintaeoitogc@gmail.com, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Miguel Ojeda Subject: [PATCH V3 1/2] rust: module: change author to an array Date: Thu, 20 Feb 2025 13:19:50 -0300 Message-Id: <20250220161951.844367-2-trintaeoitogc@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250220161951.844367-1-trintaeoitogc@gmail.com> References: <20250220161951.844367-1-trintaeoitogc@gmail.com> 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" In the module! macro, the author field is currently of type String. Since modules can have multiple authors, this limitation prevents specifying more than one. Change the author field to Option> to allow creating modules with multiple authors. Additionally, rename the field from author to authors to make it explicit that it can refer to multiple authors. In modules that use the author field, update its value to an array of strings, and also rename it from author to authors. Suggested-by: Miguel Ojeda Link: https://github.com/Rust-for-Linux/linux/issues/244 Signed-off-by: Guilherme Giacomo Simoes --- drivers/block/rnull.rs | 2 +- rust/kernel/net/phy.rs | 4 ++-- rust/kernel/pci.rs | 2 +- rust/macros/lib.rs | 6 +++--- rust/macros/module.rs | 12 +++++++----- samples/rust/rust_driver_pci.rs | 2 +- samples/rust/rust_driver_platform.rs | 2 +- samples/rust/rust_minimal.rs | 2 +- samples/rust/rust_misc_device.rs | 2 +- samples/rust/rust_print_main.rs | 2 +- 10 files changed, 19 insertions(+), 17 deletions(-) diff --git a/drivers/block/rnull.rs b/drivers/block/rnull.rs index ddf3629d8894..d07e76ae2c13 100644 --- a/drivers/block/rnull.rs +++ b/drivers/block/rnull.rs @@ -27,7 +27,7 @@ module! { type: NullBlkModule, name: "rnull_mod", - author: "Andreas Hindborg", + authors: ["Andreas Hindborg"], description: "Rust implementation of the C null block driver", license: "GPL v2", } diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index bb654a28dab3..a59469c785e3 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -790,7 +790,7 @@ const fn as_int(&self) -> u32 { /// DeviceId::new_with_driver::() /// ], /// name: "rust_sample_phy", -/// author: "Rust for Linux Contributors", +/// authors: ["Rust for Linux Contributors"], /// description: "Rust sample PHYs driver", /// license: "GPL", /// } @@ -819,7 +819,7 @@ const fn as_int(&self) -> u32 { /// module! { /// type: Module, /// name: "rust_sample_phy", -/// author: "Rust for Linux Contributors", +/// authors: ["Rust for Linux Contributors"], /// description: "Rust sample PHYs driver", /// license: "GPL", /// } diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 4c98b5b9aa1e..f7b2743828ae 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -103,7 +103,7 @@ extern "C" fn remove_callback(pdev: *mut bindings::pci_= dev) { /// kernel::module_pci_driver! { /// type: MyDriver, /// name: "Module name", -/// author: "Author name", +/// authors: ["Author name"], /// description: "Description", /// license: "GPL v2", /// } diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs index d61bc6a56425..7ce1cb891dfb 100644 --- a/rust/macros/lib.rs +++ b/rust/macros/lib.rs @@ -36,7 +36,7 @@ /// module!{ /// type: MyModule, /// name: "my_kernel_module", -/// author: "Rust for Linux Contributors", +/// authors: ["Rust for Linux Contributors"], /// description: "My very own kernel module!", /// license: "GPL", /// alias: ["alternate_module_name"], @@ -69,7 +69,7 @@ /// module!{ /// type: MyDeviceDriverModule, /// name: "my_device_driver_module", -/// author: "Rust for Linux Contributors", +/// authors: ["Rust for Linux Contributors"], /// description: "My device driver requires firmware", /// license: "GPL", /// firmware: ["my_device_firmware1.bin", "my_device_firmware2.bin"], @@ -88,7 +88,7 @@ /// # Supported argument types /// - `type`: type which implements the [`Module`] trait (required). /// - `name`: ASCII string literal of the name of the kernel module (req= uired). -/// - `author`: string literal of the author of the kernel module. +/// - `authors`: array of ASCII string literals of the authors of the ke= rnel module. /// - `description`: string literal of the description of the kernel mod= ule. /// - `license`: ASCII string literal of the license of the kernel modul= e (required). /// - `alias`: array of ASCII string literals of the alias names of the = kernel module. diff --git a/rust/macros/module.rs b/rust/macros/module.rs index cdf94f4982df..db16f0af0855 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -94,7 +94,7 @@ struct ModuleInfo { type_: String, license: String, name: String, - author: Option, + authors: Option>, description: Option, alias: Option>, firmware: Option>, @@ -107,7 +107,7 @@ fn parse(it: &mut token_stream::IntoIter) -> Self { const EXPECTED_KEYS: &[&str] =3D &[ "type", "name", - "author", + "authors", "description", "license", "alias", @@ -135,7 +135,7 @@ fn parse(it: &mut token_stream::IntoIter) -> Self { match key.as_str() { "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)), @@ -183,8 +183,10 @@ 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(author) =3D info.author { - modinfo.emit("author", &author); + if let Some(authors) =3D info.authors { + for author in authors { + modinfo.emit("authors", &author); + } } if let Some(description) =3D info.description { modinfo.emit("description", &description); diff --git a/samples/rust/rust_driver_pci.rs b/samples/rust/rust_driver_pci= .rs index 1fb6e44f3395..364a0660a743 100644 --- a/samples/rust/rust_driver_pci.rs +++ b/samples/rust/rust_driver_pci.rs @@ -104,7 +104,7 @@ fn drop(&mut self) { kernel::module_pci_driver! { type: SampleDriver, name: "rust_driver_pci", - author: "Danilo Krummrich", + authors: ["Danilo Krummrich"], description: "Rust PCI driver", license: "GPL v2", } diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_drive= r_platform.rs index 8120609e2940..f7a0f1b29d1d 100644 --- a/samples/rust/rust_driver_platform.rs +++ b/samples/rust/rust_driver_platform.rs @@ -43,7 +43,7 @@ fn drop(&mut self) { kernel::module_platform_driver! { type: SampleDriver, name: "rust_driver_platform", - author: "Danilo Krummrich", + authors: ["Danilo Krummrich"], description: "Rust Platform driver", license: "GPL v2", } diff --git a/samples/rust/rust_minimal.rs b/samples/rust/rust_minimal.rs index 4aaf117bf8e3..1fc7a1be6b6d 100644 --- a/samples/rust/rust_minimal.rs +++ b/samples/rust/rust_minimal.rs @@ -7,7 +7,7 @@ module! { type: RustMinimal, name: "rust_minimal", - author: "Rust for Linux Contributors", + authors: ["Rust for Linux Contributors"], description: "Rust minimal sample", license: "GPL", } diff --git a/samples/rust/rust_misc_device.rs b/samples/rust/rust_misc_devi= ce.rs index 40ad7266c225..d3785e7c0330 100644 --- a/samples/rust/rust_misc_device.rs +++ b/samples/rust/rust_misc_device.rs @@ -116,7 +116,7 @@ module! { type: RustMiscDeviceModule, name: "rust_misc_device", - author: "Lee Jones", + authors: ["Lee Jones"], description: "Rust misc device sample", license: "GPL", } diff --git a/samples/rust/rust_print_main.rs b/samples/rust/rust_print_main= .rs index 7e8af5f176a3..8ea95e8c2f36 100644 --- a/samples/rust/rust_print_main.rs +++ b/samples/rust/rust_print_main.rs @@ -8,7 +8,7 @@ module! { type: RustPrint, name: "rust_print", - author: "Rust for Linux Contributors", + authors: ["Rust for Linux Contributors"], description: "Rust printing macros sample", license: "GPL", } --=20 2.34.1 From nobody Tue Dec 16 11:04:29 2025 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 15B841C3BE0; Thu, 20 Feb 2025 16:20:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740068425; cv=none; b=hYPNc9malfd8T7y6zCwqEYbKmd0Em8Fq0ajYUnmGXc1GHgQZeXq/4W7ztaG3JfM+OHOz6YGB2VHQErF44U94UKY/MJWB5AMWBwRKblNNS7kwa2RZcF93veJzDveIFabD8TDW1iC10nJAoY1YiA4RD0xzPGHBtH+LZ3urlcUQKQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740068425; c=relaxed/simple; bh=guogj3y+P7Pi0BeCcNdzvEnqnzDhTZwGUnlfgQM1mLM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iVfcpBK74GwW+5WKlsUgYb9tacvJy/jwF8GbusZJzZ5EE/DAuLR9AGram4Ko81muc77iedgu2yk8G/YoroUjmshRv97LkF+dd2LVdHXGcmsO7daMJ7FQVuXwB4bh2CUZYZpLIKGajbTibkunC2HaIGFP8lc6RYYV7pvHfKuVuC8= 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=mYe2WYKU; arc=none smtp.client-ip=209.85.214.181 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="mYe2WYKU" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-220ec47991aso15620885ad.1; Thu, 20 Feb 2025 08:20:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740068423; x=1740673223; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=m35314KpzK46gpcYRFPo8w1pzpvFqAfLP65RS4pzhwc=; b=mYe2WYKUKBKEDttU0OluYs1C0FctLv+0ZeJkgGOq6vgapmYQoAQtyyhUM8dR+Td/2C xnuDln74hACIMryxRo9IE5ZykWOAiXzirgvAkgiCcPjTCHUlRJmUSxS1VydAPL9KTCC4 B49kt+/PE2nC8FmsBdpViWl4y6xSYMkXQ1UlSnWGeiCpgkXMxnM0lW6lxIvtGLnyCflf KL2gKOyfn8Ae6wm9hks797dMQEladCJbyusOp0245vCCqAT76VaWOVllEw6zGVWZ/mpw LHL55yizRC7Q6DZQJKbEHqLtPQ8ZroN2tj79aPMN+x7RkUmHPHboR5QhKLD/LefaIpaf 3tlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740068423; x=1740673223; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m35314KpzK46gpcYRFPo8w1pzpvFqAfLP65RS4pzhwc=; b=gEGBnYyRWSpv6RRJXg7XUoZ++Ax0kjLKqaDGaQ9AhqL0WdFZ663YB93mlO2XF9BKFZ 7qFq3Lpz7JLMKkHHoYAWBQ5TQS3eapDKlYlF6blg2o3fSVdkCQL5byvs/aiXsciIvjBp siANLRO0/TPlwbGwPUcQVIuwrpT/jTpbGMO7GmjC/2MgY1uOze+bXpRO/cK7ebGwIrYw N+t+Nz3ln1h8ZDqQ4QS6FVkDzhOmo87E+U2oW6HYo0s8k3mYk3mz2IvudKM4p7UjOem/ gPZoxNlV7/NPV0vgSfuCxiMcS9G1bOAlmzuClHgX0VGPqyahRygkGTjUwpoQxg//MZw2 hunw== X-Forwarded-Encrypted: i=1; AJvYcCUG+adkXveGjCTWJvAsrj4BiLd+qjCe6BkYa4aVoSn8JnuSIBJ9Eh2UKUWZQstCu9XpDi6KYLMSfjs4rgE=@vger.kernel.org, AJvYcCXr2h+Yao/E5KOEN9UQGLXkod1zCNA/egIRYz10JeGRTKB5zwMg//tOZ6TobXi7RDX8VRcDlRzwLyGRPXC4VZs=@vger.kernel.org X-Gm-Message-State: AOJu0YzsmRxe2jwPTy5Za0a5wRM6AY3ep8iAT+5kAJ8G5VIh1CZ0Lrs2 cYuRQ6A5ahlibWxhlAYpud20Gu2ZA846/7EENWbpxxmtisn0K81Nr52uL743 X-Gm-Gg: ASbGncvITExozqzuqFSILcR4QTo7tYcoc7Gz29Ydux07Ooj3diqToGziz8gZJONbg/4 5B0+0yDN+O4etJQ0YogEBGDoG5in1eDNhH1xZB5pmkzqJ97M/8n4DNbjNDcDOVpQsLZFNT4g9iH fHSQDVrqCa0EIRXqOkPW7Z/mO2nsBHEW0RGy0ntFdTuzSV17ZNfHGr+oYtG2RjJlApK53GrLXxU lQC8wYqVMfYM/KTemaQ6eSQu56zbyO1WeoHRAcMw5Bw/kvb0Dkf78kYlxBOsWmwAWs5zA7syb/P BwU2U1aQ/NKp/Va1WauERQs= X-Google-Smtp-Source: AGHT+IHmSIiGta3r3CZMbfAGsZelk/nWOw+xjsGTGZkfR+siWKpKItpXaxt9bzaRT/MhG2oMGz91fQ== X-Received: by 2002:a17:902:d50d:b0:21f:bd66:cafa with SMTP id d9443c01a7336-22170968ad1mr128803405ad.17.1740068423004; Thu, 20 Feb 2025 08:20:23 -0800 (PST) Received: from linuxsimoes.. ([177.21.141.136]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d7a540aasm120910545ad.245.2025.02.20.08.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2025 08:20:22 -0800 (PST) From: Guilherme Giacomo Simoes To: a.hindborg@kernel.org, alex.gaynor@gmail.com, aliceryhl@google.com, apw@canonical.com, arnd@arndb.de, aswinunni01@gmail.com, axboe@kernel.dk, benno.lossin@proton.me, bhelgaas@google.com, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, dakr@kernel.org, dwaipayanray1@gmail.com, ethan.twardy@gmail.com, fujita.tomonori@gmail.com, gary@garyguo.net, gregkh@linuxfoundation.org, joe@perches.com, lukas.bulwahn@gmail.com, ojeda@kernel.org, pbonzini@redhat.com, tmgross@umich.edu, walmeida@microsoft.com Cc: trintaeoitogc@gmail.com, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 2/2] checkpatch: throw error for malformed arrays Date: Thu, 20 Feb 2025 13:19:51 -0300 Message-Id: <20250220161951.844367-3-trintaeoitogc@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250220161951.844367-1-trintaeoitogc@gmail.com> References: <20250220161951.844367-1-trintaeoitogc@gmail.com> 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" Implement a check to ensure these fields are correctly formatted. If a line contains one of these keys that should be of type Vec, use a regex to verify whether the array holds multiple values. * If the array contains more than one value, enforce vertical formatting * If the array has only one value, it can remain on the same line Signed-off-by: Guilherme Giacomo Simoes --- scripts/checkpatch.pl | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 7b28ad331742..1133fe68054b 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2775,6 +2775,9 @@ sub process { $realcnt =3D 0; $linenr =3D 0; $fixlinenr =3D -1; + + my %array_parse_module; + foreach my $line (@lines) { $linenr++; $fixlinenr++; @@ -3567,6 +3570,46 @@ sub process { # ignore non-hunk lines and lines being removed next if (!$hunk_line || $line =3D~ /^-/); =20 +# check if arrays has more than one value in the same line + my $inline =3D 0; + my $key =3D ""; + my $add_line =3D $line =3D~ /^\+/; + + if ($line =3D~ /\s*.*\b(author|alias|firmware)\s*:\s*\[/) { + $inline =3D 1; + $array_parse_module{$1} =3D 1; + } + + my @keys =3D keys %array_parse_module; + if (@keys) { + $key =3D $keys[0]; + } + + if ($add_line && $key) { + my $herevet =3D "$here\n" . cat_vet($rawline) . "\n"; + + my $counter =3D () =3D $line =3D~ /"/g; + my $more_than_one =3D $counter > 2; + if ($more_than_one) { + WARN("ARRAY_MODULE_MACRO", + "Prefer a single-line value$herevet"); + } elsif ($inline && $line !~ /\]/ && $line !~ /,/ && $line =3D~ /"/) { + WARN("ARRAY_MODULE_MACRO", + "Prefer declare ] on the same line$herevet"); + } elsif (!$inline && $line =3D~ /\]/ && $line =3D~ /\"/) { + WARN("ARRAY_MODULE_MACRO", + "Prefer a new line after the last value and before ]$= herevet"); + } elsif ($inline && $line =3D~ /,/ && $line !~ /\]/) { + WARN("ARRAY_MODULE_MACRO", + "Prefer a new line after [$herevet"); + } + } + + #END OF ANALYZE FIELD + if ($line =3D~ /\]/) { + delete $array_parse_module{$key}; + } + #trailing whitespace if ($line =3D~ /^\+.*\015/) { my $herevet =3D "$here\n" . cat_vet($rawline) . "\n"; --=20 2.34.1