From nobody Mon May 25 01:16:41 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B29E36827E; Tue, 19 May 2026 18:25:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779215107; cv=none; b=swc17OWCD7zwhFeHcNeF4Ec3ff51eYjPQQ2/ntpKy+5CRAenpLoPOZjkbC/PqyW3fBYJJLKWN9w9SRhykK9z7MkkzinQYGca1BN+IaNilR0M9xlVUd9FFRP/xxd9joHOygqyR54g2G/TmqjHLbOVMTekcCnTdw6eL+rJA0fgAZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779215107; c=relaxed/simple; bh=37gkrudc3UZ+P4Z9TUfyE6f275CQW1zKf1om7jujkkA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ol9emiQDv+dMjXJWjKfiLPs6AUePWpLuWNKPWcD+0/1iA40NcKYP3KezoS5edgzbt/cO9yVSl+WA9pGDYG8O/JuE9K/+kppQbPerQIR/6TP/ohJqu2Q2d0TxkCfrdWyda37MDv8ZyjPHL/AzBRX3EWfCHqIGf8f7desVacpaPoc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=iBd/aCJR; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="iBd/aCJR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1779214557; bh=37gkrudc3UZ+P4Z9TUfyE6f275CQW1zKf1om7jujkkA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=iBd/aCJRzBCS7L4JwtMe6eu8QHEdriUOAmXfwsep/IQ0F7dllrkJDL/29dT1ovev1 OAafRb4C6wq29DdZUknRDP9deDUszKZ1vbr8CrchhSO6J5AAVG0/78QuavhKVXtQS6 KZjwaVOE683JcDaSQrOn+iqNVbwUtT+QUC+IgZ+Q= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 19 May 2026 20:15:51 +0200 Subject: [PATCH v2 1/2] PCI: hotplug: Manage hotplug slot attributes as group Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260519-sysfs-const-pci-hotplug-v2-1-16e90346a522@weissschuh.net> References: <20260519-sysfs-const-pci-hotplug-v2-0-16e90346a522@weissschuh.net> In-Reply-To: <20260519-sysfs-const-pci-hotplug-v2-0-16e90346a522@weissschuh.net> To: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779214556; l=4449; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=37gkrudc3UZ+P4Z9TUfyE6f275CQW1zKf1om7jujkkA=; b=v8UsVpKOXXUTNrRPNwO4EXyxE7INRP1HZ2DADJYghswGIS354MAQ5qq1/j97BwKYvPAO6cKFW mKtfdSbuDEOAO8VCXT2nY7U9uWAPD5x2Q80Y9ZM0e+qNyxtK+RupZoq X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Make use of 'struct attribute_group' to manage all attribute together, simplifying the lifecycle management. Signed-off-by: Thomas Wei=C3=9Fschuh --- drivers/pci/hotplug/pci_hotplug_core.c | 114 +++++++++++++----------------= ---- 1 file changed, 43 insertions(+), 71 deletions(-) diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/p= ci_hotplug_core.c index fadcf98a8a66..7c4e197f5581 100644 --- a/drivers/pci/hotplug/pci_hotplug_core.c +++ b/drivers/pci/hotplug/pci_hotplug_core.c @@ -239,10 +239,46 @@ static bool has_test_file(struct hotplug_slot *slot) return false; } =20 +static struct attribute *hotplug_slot_attrs[] =3D { + &hotplug_slot_attr_power.attr, + &hotplug_slot_attr_attention.attr, + &hotplug_slot_attr_latch.attr, + &hotplug_slot_attr_presence.attr, + &hotplug_slot_attr_test.attr, + NULL +}; + +static umode_t hotplug_slot_attr_is_visible(struct kobject *kobj, struct a= ttribute *attr, int idx) +{ + struct hotplug_slot *slot =3D to_pci_slot(kobj)->hotplug; + + if (attr =3D=3D &hotplug_slot_attr_power.attr && !has_power_file(slot)) + return 0; + + if (attr =3D=3D &hotplug_slot_attr_attention.attr && !has_attention_file(= slot)) + return 0; + + if (attr =3D=3D &hotplug_slot_attr_latch.attr && !has_latch_file(slot)) + return 0; + + if (attr =3D=3D &hotplug_slot_attr_presence.attr && !has_adapter_file(slo= t)) + return 0; + + if (attr =3D=3D &hotplug_slot_attr_test.attr && !has_test_file(slot)) + return 0; + + return attr->mode; +} + +static const struct attribute_group hotplug_slot_group =3D { + .is_visible =3D hotplug_slot_attr_is_visible, + .attrs =3D hotplug_slot_attrs, +}; + static int fs_add_slot(struct hotplug_slot *slot, struct pci_slot *pci_slo= t) { struct kobject *kobj; - int retval =3D 0; + int retval; =20 /* Create symbolic link to the hotplug driver module */ kobj =3D kset_find_obj(module_kset, slot->mod_name); @@ -254,82 +290,18 @@ static int fs_add_slot(struct hotplug_slot *slot, str= uct pci_slot *pci_slot) kobject_put(kobj); } =20 - if (has_power_file(slot)) { - retval =3D sysfs_create_file(&pci_slot->kobj, - &hotplug_slot_attr_power.attr); - if (retval) - goto exit_power; - } - - if (has_attention_file(slot)) { - retval =3D sysfs_create_file(&pci_slot->kobj, - &hotplug_slot_attr_attention.attr); - if (retval) - goto exit_attention; - } - - if (has_latch_file(slot)) { - retval =3D sysfs_create_file(&pci_slot->kobj, - &hotplug_slot_attr_latch.attr); - if (retval) - goto exit_latch; - } - - if (has_adapter_file(slot)) { - retval =3D sysfs_create_file(&pci_slot->kobj, - &hotplug_slot_attr_presence.attr); - if (retval) - goto exit_adapter; - } - - if (has_test_file(slot)) { - retval =3D sysfs_create_file(&pci_slot->kobj, - &hotplug_slot_attr_test.attr); - if (retval) - goto exit_test; + retval =3D sysfs_create_group(&pci_slot->kobj, &hotplug_slot_group); + if (retval) { + sysfs_remove_link(&pci_slot->kobj, "module"); + return retval; } =20 - goto exit; - -exit_test: - if (has_adapter_file(slot)) - sysfs_remove_file(&pci_slot->kobj, - &hotplug_slot_attr_presence.attr); -exit_adapter: - if (has_latch_file(slot)) - sysfs_remove_file(&pci_slot->kobj, &hotplug_slot_attr_latch.attr); -exit_latch: - if (has_attention_file(slot)) - sysfs_remove_file(&pci_slot->kobj, - &hotplug_slot_attr_attention.attr); -exit_attention: - if (has_power_file(slot)) - sysfs_remove_file(&pci_slot->kobj, &hotplug_slot_attr_power.attr); -exit_power: - sysfs_remove_link(&pci_slot->kobj, "module"); -exit: - return retval; + return 0; } =20 static void fs_remove_slot(struct hotplug_slot *slot, struct pci_slot *pci= _slot) { - if (has_power_file(slot)) - sysfs_remove_file(&pci_slot->kobj, &hotplug_slot_attr_power.attr); - - if (has_attention_file(slot)) - sysfs_remove_file(&pci_slot->kobj, - &hotplug_slot_attr_attention.attr); - - if (has_latch_file(slot)) - sysfs_remove_file(&pci_slot->kobj, &hotplug_slot_attr_latch.attr); - - if (has_adapter_file(slot)) - sysfs_remove_file(&pci_slot->kobj, - &hotplug_slot_attr_presence.attr); - - if (has_test_file(slot)) - sysfs_remove_file(&pci_slot->kobj, &hotplug_slot_attr_test.attr); - + sysfs_remove_group(&pci_slot->kobj, &hotplug_slot_group); sysfs_remove_link(&pci_slot->kobj, "module"); } =20 --=20 2.54.0 From nobody Mon May 25 01:16:41 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B178367B92; Tue, 19 May 2026 18:25:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779215107; cv=none; b=C5bP13731KkVACRSuC2dEmLHRBOtU9C03DNuNAyfrod4q4tBWhsJKbUBau3Ynvg5FpXRK8Hc2Azk9y3wjXdhitrxO/sdDvRLTwEFM2lRV5GAwktahZDSaZldn6j7dU4wzPGtqCaossf/mbdseLc0zv27VhnP9dhQM0DPGWxluNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779215107; c=relaxed/simple; bh=0Igx9aTadXmb6OTo5npSkahdkSVxYqTYgPLzf5KhhnA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Mt86RR4NpRVRIvk/abJ+vASIvIziWgjBe4NPPs8Dmv0bPrWAwWL/Iw9Mnb5Uqu8niVt3ru6AciXimVRG88uo3uC4G3KJOo4qFLU8RZ6e0SZpuXp7mljacqWXFY8yqnAFjmRXMKKushCSJESWgQ2pD+fPeJq8LwxQHvm7LqlMXDE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=J1vU355U; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="J1vU355U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1779214557; bh=0Igx9aTadXmb6OTo5npSkahdkSVxYqTYgPLzf5KhhnA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=J1vU355UglbG8HytnPhUQ5qXiPaznmWT4cWuT7A95hH7e5zyx2bZL8dyHSM5klBkJ DfodJnbpzeouauu6toAFXK3L3w5eGeeAUuudCgyL3foj79gbLJ+P2Z/e87dLj8+wZC ySsROu9T/jejgdBxU1ERoomtAustizKSPQD8X7zA= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 19 May 2026 20:15:52 +0200 Subject: [PATCH v2 2/2] PCI: Constify slot attributes Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260519-sysfs-const-pci-hotplug-v2-2-16e90346a522@weissschuh.net> References: <20260519-sysfs-const-pci-hotplug-v2-0-16e90346a522@weissschuh.net> In-Reply-To: <20260519-sysfs-const-pci-hotplug-v2-0-16e90346a522@weissschuh.net> To: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779214556; l=6227; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=0Igx9aTadXmb6OTo5npSkahdkSVxYqTYgPLzf5KhhnA=; b=WlP8rCYG0gLbEH08CE6dD5I6KxfRxyzt6WN8thfg6T9qfuSj2d7gie0xWeMhdlb1sFoCkVmyu DfX08TGKB2oCVyNlTKR/Jw0GQ0ejYri553C1MHc+4ZHFPGTLJgLhqhH X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The attribute struct are never modified, mark them as const. Signed-off-by: Thomas Wei=C3=9Fschuh --- drivers/pci/hotplug/pci_hotplug_core.c | 19 ++++++++++--------- drivers/pci/pci.h | 2 +- drivers/pci/slot.c | 14 +++++++------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/p= ci_hotplug_core.c index 7c4e197f5581..cdf3293aade7 100644 --- a/drivers/pci/hotplug/pci_hotplug_core.c +++ b/drivers/pci/hotplug/pci_hotplug_core.c @@ -97,7 +97,7 @@ static ssize_t power_write_file(struct pci_slot *pci_slot= , const char *buf, return count; } =20 -static struct pci_slot_attribute hotplug_slot_attr_power =3D { +static const struct pci_slot_attribute hotplug_slot_attr_power =3D { .attr =3D {.name =3D "power", .mode =3D S_IFREG | S_IRUGO | S_IWUSR}, .show =3D power_read_file, .store =3D power_write_file @@ -136,7 +136,7 @@ static ssize_t attention_write_file(struct pci_slot *pc= i_slot, const char *buf, return count; } =20 -static struct pci_slot_attribute hotplug_slot_attr_attention =3D { +static const struct pci_slot_attribute hotplug_slot_attr_attention =3D { .attr =3D {.name =3D "attention", .mode =3D S_IFREG | S_IRUGO | S_IWUSR}, .show =3D attention_read_file, .store =3D attention_write_file @@ -154,7 +154,7 @@ static ssize_t latch_read_file(struct pci_slot *pci_slo= t, char *buf) return sysfs_emit(buf, "%d\n", value); } =20 -static struct pci_slot_attribute hotplug_slot_attr_latch =3D { +static const struct pci_slot_attribute hotplug_slot_attr_latch =3D { .attr =3D {.name =3D "latch", .mode =3D S_IFREG | S_IRUGO}, .show =3D latch_read_file, }; @@ -171,7 +171,7 @@ static ssize_t presence_read_file(struct pci_slot *pci_= slot, char *buf) return sysfs_emit(buf, "%d\n", value); } =20 -static struct pci_slot_attribute hotplug_slot_attr_presence =3D { +static const struct pci_slot_attribute hotplug_slot_attr_presence =3D { .attr =3D {.name =3D "adapter", .mode =3D S_IFREG | S_IRUGO}, .show =3D presence_read_file, }; @@ -196,7 +196,7 @@ static ssize_t test_write_file(struct pci_slot *pci_slo= t, const char *buf, return count; } =20 -static struct pci_slot_attribute hotplug_slot_attr_test =3D { +static const struct pci_slot_attribute hotplug_slot_attr_test =3D { .attr =3D {.name =3D "test", .mode =3D S_IFREG | S_IRUGO | S_IWUSR}, .store =3D test_write_file }; @@ -239,7 +239,7 @@ static bool has_test_file(struct hotplug_slot *slot) return false; } =20 -static struct attribute *hotplug_slot_attrs[] =3D { +static const struct attribute *const hotplug_slot_attrs[] =3D { &hotplug_slot_attr_power.attr, &hotplug_slot_attr_attention.attr, &hotplug_slot_attr_latch.attr, @@ -248,7 +248,8 @@ static struct attribute *hotplug_slot_attrs[] =3D { NULL }; =20 -static umode_t hotplug_slot_attr_is_visible(struct kobject *kobj, struct a= ttribute *attr, int idx) +static umode_t hotplug_slot_attr_is_visible(struct kobject *kobj, const st= ruct attribute *attr, + int idx) { struct hotplug_slot *slot =3D to_pci_slot(kobj)->hotplug; =20 @@ -271,8 +272,8 @@ static umode_t hotplug_slot_attr_is_visible(struct kobj= ect *kobj, struct attribu } =20 static const struct attribute_group hotplug_slot_group =3D { - .is_visible =3D hotplug_slot_attr_is_visible, - .attrs =3D hotplug_slot_attrs, + .is_visible_const =3D hotplug_slot_attr_is_visible, + .attrs_const =3D hotplug_slot_attrs, }; =20 static int fs_add_slot(struct hotplug_slot *slot, struct pci_slot *pci_slo= t) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 4a14f88e543a..3ca3832c7267 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -478,7 +478,7 @@ struct pci_slot_attribute { ssize_t (*show)(struct pci_slot *, char *); ssize_t (*store)(struct pci_slot *, const char *, size_t); }; -#define to_pci_slot_attr(s) container_of(s, struct pci_slot_attribute, att= r) +#define to_pci_slot_attr(s) container_of_const(s, struct pci_slot_attribut= e, attr) =20 enum pci_bar_type { pci_bar_unknown, /* Standard PCI BAR probe */ diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c index 6d5cd37bfb1e..7929bb87b195 100644 --- a/drivers/pci/slot.c +++ b/drivers/pci/slot.c @@ -18,7 +18,7 @@ static ssize_t pci_slot_attr_show(struct kobject *kobj, struct attribute *attr, char *buf) { struct pci_slot *slot =3D to_pci_slot(kobj); - struct pci_slot_attribute *attribute =3D to_pci_slot_attr(attr); + const struct pci_slot_attribute *attribute =3D to_pci_slot_attr(attr); return attribute->show ? attribute->show(slot, buf) : -EIO; } =20 @@ -26,7 +26,7 @@ static ssize_t pci_slot_attr_store(struct kobject *kobj, struct attribute *attr, const char *buf, size_t len) { struct pci_slot *slot =3D to_pci_slot(kobj); - struct pci_slot_attribute *attribute =3D to_pci_slot_attr(attr); + const struct pci_slot_attribute *attribute =3D to_pci_slot_attr(attr); return attribute->store ? attribute->store(slot, buf, len) : -EIO; } =20 @@ -93,14 +93,14 @@ static void pci_slot_release(struct kobject *kobj) kfree(slot); } =20 -static struct pci_slot_attribute pci_slot_attr_address =3D +static const struct pci_slot_attribute pci_slot_attr_address =3D __ATTR(address, S_IRUGO, address_read_file, NULL); -static struct pci_slot_attribute pci_slot_attr_max_speed =3D +static const struct pci_slot_attribute pci_slot_attr_max_speed =3D __ATTR(max_bus_speed, S_IRUGO, max_speed_read_file, NULL); -static struct pci_slot_attribute pci_slot_attr_cur_speed =3D +static const struct pci_slot_attribute pci_slot_attr_cur_speed =3D __ATTR(cur_bus_speed, S_IRUGO, cur_speed_read_file, NULL); =20 -static struct attribute *pci_slot_default_attrs[] =3D { +static const struct attribute *const pci_slot_default_attrs[] =3D { &pci_slot_attr_address.attr, &pci_slot_attr_max_speed.attr, &pci_slot_attr_cur_speed.attr, @@ -108,7 +108,7 @@ static struct attribute *pci_slot_default_attrs[] =3D { }; =20 static const struct attribute_group pci_slot_default_group =3D { - .attrs =3D pci_slot_default_attrs, + .attrs_const =3D pci_slot_default_attrs, }; =20 static const struct attribute_group *pci_slot_default_groups[] =3D { --=20 2.54.0