From nobody Mon Nov 25 01:55:40 2024 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 F1A9512C473 for ; Thu, 31 Oct 2024 02:44:24 +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=1730342668; cv=none; b=pfz3gNQYvRjYoAVjz0mzdesE9EhCAqRrp0wNq6llEtzb+ZKgOs8nswfTBPCRcdG5KckLfiQJnMwB8MW/xyHpd0RgMBNf3D4by3Njqg9htl9gudtvO5/omGhBMX5H3S71euFUgKOwBa3+Srl13GNIlpVAdHk5RDfHHfC0RI6agSI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730342668; c=relaxed/simple; bh=iCkq/n0ScNs19XGEBHP6SQ4H+TMRU4fkw8iLrhzrW/Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bVlMx2SVjY/r2kEnqNBseEM1yWUDjHq79NZD3/o2/UEDBGdKGPuEWi0lpVCUzuFbMNxqXfmeAy5fsT5NzDjLd/G8+BC/DujhFfMOCFrFkrIDnSM8ZBcT+fzL9QHyWWDaEUhQdp632w056+0/Z4jukHCDHBVDZ/aGjs9fpAIrsU0= 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=l65h0Xuk; 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="l65h0Xuk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1730342662; bh=iCkq/n0ScNs19XGEBHP6SQ4H+TMRU4fkw8iLrhzrW/Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=l65h0XukiXN4BdEFyncTp/UBZ/U+9z2UHbM7gGX5BRcepfcPGG3g1bjTahnAUznic 8mEylLJBmZq0meuuE8fnMZ1FFJ6KKZwSoRC8RI1AwG2RqARi+lAt9htYpxhcRUrYgJ rtrgLQ+9pyfwJASs6Z7VnrabXJn9ic23Mzlwgeyg= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 31 Oct 2024 02:43:50 +0000 Subject: [PATCH RFC 01/10] sysfs: explicitly pass size to sysfs_add_bin_file_mode_ns() 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: <20241031-sysfs-const-bin_attr-v1-1-2281afa7f055@weissschuh.net> References: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> In-Reply-To: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Dan Williams , linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1730342657; l=3118; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=iCkq/n0ScNs19XGEBHP6SQ4H+TMRU4fkw8iLrhzrW/Q=; b=8H9UXNcwMtfvH+tc1LRO3oWJXPSganB+Ds3czbDy342RiLa9+en5+xsI7j/4TFrUP1CsXi9/A PqXxTTG2hkSAEv9yr5X59lCoVpcfZm5RM1rFjc0VgO4YYnApqsTSARS X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Upcoming changes to the sysfs core require the size of the created file to be overridable by the caller. Add a parameter to enable this. For now keep using attr->size in all cases. Signed-off-by: Thomas Wei=C3=9Fschuh --- fs/sysfs/file.c | 8 ++++---- fs/sysfs/group.c | 3 ++- fs/sysfs/sysfs.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index d1995e2d6c943a644ff9f34cf2488864d57daf81..6d39696b43069010b0ad0bdaadc= f9002cb70c92c 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -315,7 +315,7 @@ int sysfs_add_file_mode_ns(struct kernfs_node *parent, } =20 int sysfs_add_bin_file_mode_ns(struct kernfs_node *parent, - const struct bin_attribute *battr, umode_t mode, + const struct bin_attribute *battr, umode_t mode, size_t size, kuid_t uid, kgid_t gid, const void *ns) { const struct attribute *attr =3D &battr->attr; @@ -340,7 +340,7 @@ int sysfs_add_bin_file_mode_ns(struct kernfs_node *pare= nt, #endif =20 kn =3D __kernfs_create_file(parent, attr->name, mode & 0777, uid, gid, - battr->size, ops, (void *)attr, ns, key); + size, ops, (void *)attr, ns, key); if (IS_ERR(kn)) { if (PTR_ERR(kn) =3D=3D -EEXIST) sysfs_warn_dup(parent, attr->name); @@ -580,8 +580,8 @@ int sysfs_create_bin_file(struct kobject *kobj, return -EINVAL; =20 kobject_get_ownership(kobj, &uid, &gid); - return sysfs_add_bin_file_mode_ns(kobj->sd, attr, attr->attr.mode, uid, - gid, NULL); + return sysfs_add_bin_file_mode_ns(kobj->sd, attr, attr->attr.mode, + attr->size, uid, gid, NULL); } EXPORT_SYMBOL_GPL(sysfs_create_bin_file); =20 diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index d22ad67a0f3291f4702f494939528d5d13c31fae..45b2e92941da1f49dcc71af3781= 317c61480c956 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -87,6 +87,7 @@ static int create_files(struct kernfs_node *parent, struc= t kobject *kobj, if (grp->bin_attrs) { for (i =3D 0, bin_attr =3D grp->bin_attrs; *bin_attr; i++, bin_attr++) { umode_t mode =3D (*bin_attr)->attr.mode; + size_t size =3D (*bin_attr)->size; =20 if (update) kernfs_remove_by_name(parent, @@ -104,7 +105,7 @@ static int create_files(struct kernfs_node *parent, str= uct kobject *kobj, =20 mode &=3D SYSFS_PREALLOC | 0664; error =3D sysfs_add_bin_file_mode_ns(parent, *bin_attr, - mode, uid, gid, + mode, size, uid, gid, NULL); if (error) break; diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h index 3f28c9af57562f61a00a47935579f0939cbfd4dc..8e012f25e1c06e802c3138cc271= 5b46c1f67fa48 100644 --- a/fs/sysfs/sysfs.h +++ b/fs/sysfs/sysfs.h @@ -31,7 +31,7 @@ int sysfs_add_file_mode_ns(struct kernfs_node *parent, const struct attribute *attr, umode_t amode, kuid_t uid, kgid_t gid, const void *ns); int sysfs_add_bin_file_mode_ns(struct kernfs_node *parent, - const struct bin_attribute *battr, umode_t mode, + const struct bin_attribute *battr, umode_t mode, size_t size, kuid_t uid, kgid_t gid, const void *ns); =20 /* --=20 2.47.0 From nobody Mon Nov 25 01:55:40 2024 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 ACE527E59A for ; Thu, 31 Oct 2024 02:44:24 +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=1730342668; cv=none; b=amAxASRh1glpQ9iwo12MaLVTLRt7BRqVeWhDRWKxqNL4SOQUpJX9Y1d7q6wspguX2PudeJl50egghokG1p7gCRzaaBKrzE+j4Ku44BeK9GFBlTQxWqNnmcGVhm1dFFmrTnY7I1fJ7i65KI6ylphn7KsWyj3JTwuJ7egYfkNLddA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730342668; c=relaxed/simple; bh=vzqsMVfnVQ7g+xXQgYvHKh8WFOGMi08tymfd1lvAle8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QPZ13rBv+5LJPZ6BNA+Cy1Uqe1zthGvY/rD6AWpJNT1EwXEybcN9BkpzG+Wu7sOvDywx1bBMRBcaNV+3TrtFC9SQzTsO8DApd3u/oU4mGv3LoSrHogxi3zR8GFxJ6WnapObnKCyGVRXb9SGLDrzQ8DtA489WhO1jWCmOTu+Qdrk= 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=hqz69wnP; 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="hqz69wnP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1730342661; bh=vzqsMVfnVQ7g+xXQgYvHKh8WFOGMi08tymfd1lvAle8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hqz69wnPhwAu/R2yl9FafiTmE3ftGMxNvniwFW7b+WBEfEHWJkTJnzfh+AMT4PUcp fxwN6Y33Y4av+3Iz4J1U7oNqe9D66o9anO5fv37wKpz+15Hwya8iTuzvXYMLoZUxq+ DYW6C6y2ytQkhHPHsXxZdV1LgEODdSAbEZmKg4Vs= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 31 Oct 2024 02:43:51 +0000 Subject: [PATCH RFC 02/10] sysfs: introduce callback attribute_group::bin_size 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: <20241031-sysfs-const-bin_attr-v1-2-2281afa7f055@weissschuh.net> References: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> In-Reply-To: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Dan Williams , linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1730342657; l=2296; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=vzqsMVfnVQ7g+xXQgYvHKh8WFOGMi08tymfd1lvAle8=; b=jv82MGxDAxK1IVQpXdQfHZBNa86gVEhZFlqE6iiE9c2P5m+0L+5OaEswu8Yg/0Z7iuTnWkY16 z1sOpxMuxN0AHDvSH9oXv3mmJPSdJ4XbY6qZXC+cUQTO+BM5yv5JV/V X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Several drivers need to dynamically calculate the size of an binary attribute. Currently this is done by assigning attr->size from the is_bin_visible() callback. This has drawbacks: * It is not documented. * A single attribute can be instantiated multiple times, overwriting the shared size field. * It prevents the structure to be moved to read-only memory. Introduce a new dedicated callback to calculate the size of the attribute. Signed-off-by: Thomas Wei=C3=9Fschuh --- fs/sysfs/group.c | 2 ++ include/linux/sysfs.h | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 45b2e92941da1f49dcc71af3781317c61480c956..8b01a7eda5fb3239e138372417d= 01967c7a3f122 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -98,6 +98,8 @@ static int create_files(struct kernfs_node *parent, struc= t kobject *kobj, if (!mode) continue; } + if (grp->bin_size) + size =3D grp->bin_size(kobj, *bin_attr, i); =20 WARN(mode & ~(SYSFS_PREALLOC | 0664), "Attribute %s: Invalid permissions 0%o\n", diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index c4e64dc112063f7cb89bf66059d0338716089e87..4746cccb95898b24df6f53de942= 1ea7649b5568f 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -87,6 +87,11 @@ do { \ * SYSFS_GROUP_VISIBLE() when assigning this callback to * specify separate _group_visible() and _attr_visible() * handlers. + * @bin_size: + * Optional: Function to return the size of a binary attribute + * of the group. Will be called repeatedly for each binary + * attribute in the group. Overwrites the size field embedded + * inside the attribute itself. * @attrs: Pointer to NULL terminated list of attributes. * @bin_attrs: Pointer to NULL terminated list of binary attributes. * Either attrs or bin_attrs or both must be provided. @@ -97,6 +102,9 @@ struct attribute_group { struct attribute *, int); umode_t (*is_bin_visible)(struct kobject *, struct bin_attribute *, int); + size_t (*bin_size)(struct kobject *, + const struct bin_attribute *, + int); struct attribute **attrs; struct bin_attribute **bin_attrs; }; --=20 2.47.0 From nobody Mon Nov 25 01:55:40 2024 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 ACDFE4689 for ; Thu, 31 Oct 2024 02:44:24 +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=1730342668; cv=none; b=UFr3Js0V+dX0fHeiAScvNZy2tgqNBX0a827OBJ+RbKwkZUzVwBG/+deqSSOgPuWt2cKCngSCI4vQZPPLHFtqXLwlxvmdOphTGVO+YL0R0GEtA818FSc0toIMBb0oUFuIbWZtc0SR1iKX23YXFtub9jwNsKVkhecjAVCZj0or2JI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730342668; c=relaxed/simple; bh=omnzY7OVUHnekZ/bUX8pXaM2rzeR5oe1Izmsxqjd69Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cX1rnAZfvdrbpz95rgthcssnP0HLrbnfIIxMBko1eN+6d0FXS2vxcqoV+F2kdGaVb7QyFNzi8fhlkZff4NZDDSHZd0vKuvxR3G1mEncAWEZUnyToL1XlgNKNclwNpg9+pX7judiV/CwrrmeZHTAohvpReZbbwbR6JtTV8xjwGeE= 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=b0H2NESF; 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="b0H2NESF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1730342662; bh=omnzY7OVUHnekZ/bUX8pXaM2rzeR5oe1Izmsxqjd69Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=b0H2NESFCP/uyS9vTXKfvcMQdc1trWOQ5a00Wv2bFXk4673CFixk5q3NL2TNVQxqP FzTrS3rhh3mJ9b+6uH3F7f3VD5AqjhJVXPFbOh2qDK1+X8jRQIVadIk9P/8il0jV0m tbMqJMXalEAR0SX6DfaUGMURzxEy8c9lfQPn0YZo= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 31 Oct 2024 02:43:52 +0000 Subject: [PATCH RFC 03/10] PCI/sysfs: Calculate bin_attribute size through bin_size() 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: <20241031-sysfs-const-bin_attr-v1-3-2281afa7f055@weissschuh.net> References: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> In-Reply-To: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Dan Williams , linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1730342657; l=2359; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=omnzY7OVUHnekZ/bUX8pXaM2rzeR5oe1Izmsxqjd69Q=; b=fh5azo1dxElpMiHMFwshE8J2OJOb7k7moGh24FiRi3roNkr6MrU1GAExxEW9VZdQfoLmKAhVH fOP7YRkZnmXDa/4zGUonCCqozMGhWUxW1EJdAGU5PxbuH3aTYur4C9u X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Stop abusing the is_bin_visible() callback to calculate the attribute size. Instead use the new, dedicated bin_size() one. Signed-off-by: Thomas Wei=C3=9Fschuh --- drivers/pci/pci-sysfs.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 5d0f4db1cab78674c5e5906f321bf7a57b742983..040f01b2b999175e8d98b05851e= dc078bbabbe0d 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -818,21 +818,20 @@ static struct bin_attribute *pci_dev_config_attrs[] = =3D { NULL, }; =20 -static umode_t pci_dev_config_attr_is_visible(struct kobject *kobj, - struct bin_attribute *a, int n) +static size_t pci_dev_config_attr_bin_size(struct kobject *kobj, + const struct bin_attribute *a, + int n) { struct pci_dev *pdev =3D to_pci_dev(kobj_to_dev(kobj)); =20 - a->size =3D PCI_CFG_SPACE_SIZE; if (pdev->cfg_size > PCI_CFG_SPACE_SIZE) - a->size =3D PCI_CFG_SPACE_EXP_SIZE; - - return a->attr.mode; + return PCI_CFG_SPACE_EXP_SIZE; + return PCI_CFG_SPACE_SIZE; } =20 static const struct attribute_group pci_dev_config_attr_group =3D { .bin_attrs =3D pci_dev_config_attrs, - .is_bin_visible =3D pci_dev_config_attr_is_visible, + .bin_size =3D pci_dev_config_attr_bin_size, }; =20 /* @@ -1330,21 +1329,26 @@ static umode_t pci_dev_rom_attr_is_visible(struct k= object *kobj, struct bin_attribute *a, int n) { struct pci_dev *pdev =3D to_pci_dev(kobj_to_dev(kobj)); - size_t rom_size; =20 /* If the device has a ROM, try to expose it in sysfs. */ - rom_size =3D pci_resource_len(pdev, PCI_ROM_RESOURCE); - if (!rom_size) + if (!pci_resource_end(pdev, PCI_ROM_RESOURCE)) return 0; =20 - a->size =3D rom_size; - return a->attr.mode; } =20 +static size_t pci_dev_rom_attr_bin_size(struct kobject *kobj, + const struct bin_attribute *a, int n) +{ + struct pci_dev *pdev =3D to_pci_dev(kobj_to_dev(kobj)); + + return pci_resource_len(pdev, PCI_ROM_RESOURCE); +} + static const struct attribute_group pci_dev_rom_attr_group =3D { .bin_attrs =3D pci_dev_rom_attrs, .is_bin_visible =3D pci_dev_rom_attr_is_visible, + .bin_size =3D pci_dev_rom_attr_bin_size, }; =20 static ssize_t reset_store(struct device *dev, struct device_attribute *at= tr, --=20 2.47.0 From nobody Mon Nov 25 01:55:40 2024 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 CAA741332A1 for ; Thu, 31 Oct 2024 02:44:29 +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=1730342671; cv=none; b=j8xc86Ns+XzWn53qvsjad/uJ+xmMRDgV7rmAUJGqpMTHrsBGNRGXGuluGfc64N7l2Sly05kp3qOXcC4LrtaOCAqL+uXJn8Inx6Ql4hyxK8amwhMNCy0G69J+AcGsUNGDTyMSwnkfOauojLjv4qC0mNc86c2i/vT4OK/X7e9PYdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730342671; c=relaxed/simple; bh=zDhPVchfMys7HnsVtwZsrXjRXhl5fZsRZ1XGARPtegE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=irRIGTMkIyYO7EkPsKuMJClgQ42+q2uGgef5fpvaEKk+fs2zNf1ON5AxJhEK9EnHsTtyUboUpCxkfzDtP4Xt9KtKrKoTN9n6jM09/phoZgQ9RCBq1MJJmvi83ZkeUoRJ7gJnMWw4LJJU3DTRpoHM2/4S98I+NxN8BAzRlY12bGE= 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=nF/vI4jO; 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="nF/vI4jO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1730342666; bh=zDhPVchfMys7HnsVtwZsrXjRXhl5fZsRZ1XGARPtegE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=nF/vI4jOoNK4bsUA1uXozLwZNamxvLoWdm3DBt/vN2RlE8HCKyfhj/C4NIyaC4Muf ky7SIbCnrf3Bejyx+omQl03OowNEJuxhgs9LJrlcXk/b+QA6XcaswcTbWBXwpHzRlz /mCL/qPDUGX3uZ3sMaef5G1nxxBKhKNv0ZNpmYTg= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 31 Oct 2024 02:43:53 +0000 Subject: [PATCH RFC 04/10] nvmem: core: calculate bin_attribute size through bin_size() 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: <20241031-sysfs-const-bin_attr-v1-4-2281afa7f055@weissschuh.net> References: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> In-Reply-To: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Dan Williams , linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1730342657; l=1407; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=zDhPVchfMys7HnsVtwZsrXjRXhl5fZsRZ1XGARPtegE=; b=py0ESqotq+DRkCZXpG3Al8GwMMmbL12JSSs4zJ1sWJWNsihxUzqeHp+RZRJqZ56y4Qjt4o7s3 /rn2qm/HpD1CFlbGh0xVV5ZU4SqbtQ1lGCf0HRhxROhOYJB8TgqMLnH X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Stop abusing the is_bin_visible() callback to calculate the attribute size. Instead use the new, dedicated bin_size() one. Signed-off-by: Thomas Wei=C3=9Fschuh --- drivers/nvmem/core.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 33ffa2aa4c1152398ec66b8dd7b30384c5346a6e..63370c76394ee9b8d514da07477= 9617cef67c311 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -303,11 +303,19 @@ static umode_t nvmem_bin_attr_is_visible(struct kobje= ct *kobj, struct device *dev =3D kobj_to_dev(kobj); struct nvmem_device *nvmem =3D to_nvmem_device(dev); =20 - attr->size =3D nvmem->size; - return nvmem_bin_attr_get_umode(nvmem); } =20 +static size_t nvmem_bin_attr_size(struct kobject *kobj, + const struct bin_attribute *attr, + int i) +{ + struct device *dev =3D kobj_to_dev(kobj); + struct nvmem_device *nvmem =3D to_nvmem_device(dev); + + return nvmem->size; +} + static umode_t nvmem_attr_is_visible(struct kobject *kobj, struct attribute *attr, int i) { @@ -383,6 +391,7 @@ static const struct attribute_group nvmem_bin_group =3D= { .bin_attrs =3D nvmem_bin_attributes, .attrs =3D nvmem_attrs, .is_bin_visible =3D nvmem_bin_attr_is_visible, + .bin_size =3D nvmem_bin_attr_size, .is_visible =3D nvmem_attr_is_visible, }; =20 --=20 2.47.0 From nobody Mon Nov 25 01:55:40 2024 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 E951A10A3E for ; Thu, 31 Oct 2024 02:44:27 +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=1730342670; cv=none; b=GKkqLdR0BR4gZgdOTdJiJV2QVRODRZHiLy8MxNfehlzNpPB4ZDA5+KPXCw+3jTv4U0OZPC62ZtJ2QmI0TsrnlQd39CfUKEhxToHyelNWWRGCgz5l8byEqKAhg0yW9DR96MUbX8FaWV3VPUt6h91z0xVnGErjWvPFcV18IagV6Us= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730342670; c=relaxed/simple; bh=p7EKoDjpwnqyDMvTqsimORFFg1riJU8XKmsg0+Giqpo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kn8Pmnu7OG7977wI74X4P/cRiOEw2Zar9KTdf/PKuYEuHTrvSplkqLujxWUBjKUOZ4km60FDEDYglsd/SIgzZq/ipyHnmJT5wgMXOAJdGwfhaamND4scnQNeSb7RS2iZyoGnoURohwD7xPfmIEloiMrqI15gbih88URMCW6U/jI= 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=R8mMj1ng; 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="R8mMj1ng" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1730342665; bh=p7EKoDjpwnqyDMvTqsimORFFg1riJU8XKmsg0+Giqpo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=R8mMj1ngxhvqUAuT5ez/2BOsCNA8Az14hAqtgE4NzRPx2ZHJPXOh9uU2j2MxhCvi1 1C5dVjyxe1AZYyjSjQlrZ6WdxW5MXweoUIjcLgTLYFSNHiTD6n2r1Iiy/853ugAuHw rpciPOr3CRvD8ZO7WZZsfzIS1KTUg6KonTc+x+g4= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 31 Oct 2024 02:43:54 +0000 Subject: [PATCH RFC 05/10] sysfs: treewide: constify attribute callback of bin_is_visible() 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: <20241031-sysfs-const-bin_attr-v1-5-2281afa7f055@weissschuh.net> References: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> In-Reply-To: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Dan Williams , linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1730342657; l=10037; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=p7EKoDjpwnqyDMvTqsimORFFg1riJU8XKmsg0+Giqpo=; b=BMpqyoXfTRVDZbZQc+boC7moxXAfgSr/uUDETPcmrPqFq9/LRUZcABjh/lhqXnDrm8onN7ndP mFFuNE+Nq5sApT70sUR50a52CGZd79d9DvymWDGkO8EoVLmvouuf0oO X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The is_bin_visible() callbacks should not modify the struct bin_attribute passed as argument. Enforce this by marking the argument as const. As there are not many callback implementers perform this change throughout the tree at once. Signed-off-by: Thomas Wei=C3=9Fschuh --- drivers/cxl/port.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 2 +- drivers/infiniband/hw/qib/qib_sysfs.c | 2 +- drivers/mtd/spi-nor/sysfs.c | 2 +- drivers/nvmem/core.c | 3 ++- drivers/pci/pci-sysfs.c | 2 +- drivers/pci/vpd.c | 2 +- drivers/platform/x86/amd/hsmp.c | 2 +- drivers/platform/x86/intel/sdsi.c | 2 +- drivers/scsi/scsi_sysfs.c | 2 +- drivers/usb/core/sysfs.c | 2 +- include/linux/sysfs.h | 30 +++++++++++++++--------------- 12 files changed, 27 insertions(+), 26 deletions(-) diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c index 861dde65768fe383d3ccbb49ffd31fb29aeb42e9..ed78043ec13a6f6db5f077a5679= e0342ce7f7eff 100644 --- a/drivers/cxl/port.c +++ b/drivers/cxl/port.c @@ -173,7 +173,7 @@ static ssize_t CDAT_read(struct file *filp, struct kobj= ect *kobj, static BIN_ATTR_ADMIN_RO(CDAT, 0); =20 static umode_t cxl_port_bin_attr_is_visible(struct kobject *kobj, - struct bin_attribute *attr, int i) + const struct bin_attribute *attr, int i) { struct device *dev =3D kobj_to_dev(kobj); struct cxl_port *port =3D to_cxl_port(dev); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/= amdgpu/amdgpu_psp.c index 0b28b2cf1517d130da01989df70b9dff6433edc4..c1c329eb920b52af100a93bdf00= df450e25608c4 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c @@ -3999,7 +3999,7 @@ static umode_t amdgpu_flash_attr_is_visible(struct ko= bject *kobj, struct attribu } =20 static umode_t amdgpu_bin_flash_attr_is_visible(struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, int idx) { struct device *dev =3D kobj_to_dev(kobj); diff --git a/drivers/infiniband/hw/qib/qib_sysfs.c b/drivers/infiniband/hw/= qib/qib_sysfs.c index 53ec7510e4ebfb144e79884ca7dd7d0c873bd8a7..ba2cd68b53e6c240f1afc65c640= 12c75ccf488e0 100644 --- a/drivers/infiniband/hw/qib/qib_sysfs.c +++ b/drivers/infiniband/hw/qib/qib_sysfs.c @@ -283,7 +283,7 @@ static struct bin_attribute *port_ccmgta_attributes[] = =3D { }; =20 static umode_t qib_ccmgta_is_bin_visible(struct kobject *kobj, - struct bin_attribute *attr, int n) + const struct bin_attribute *attr, int n) { struct qib_pportdata *ppd =3D qib_get_pportdata_kobj(kobj); =20 diff --git a/drivers/mtd/spi-nor/sysfs.c b/drivers/mtd/spi-nor/sysfs.c index 96064e4babf01f6950c81586764386e7671cbf97..5e9eb268073d18e0a46089000f1= 8a3200b4bf13d 100644 --- a/drivers/mtd/spi-nor/sysfs.c +++ b/drivers/mtd/spi-nor/sysfs.c @@ -87,7 +87,7 @@ static umode_t spi_nor_sysfs_is_visible(struct kobject *k= obj, } =20 static umode_t spi_nor_sysfs_is_bin_visible(struct kobject *kobj, - struct bin_attribute *attr, int n) + const struct bin_attribute *attr, int n) { struct spi_device *spi =3D to_spi_device(kobj_to_dev(kobj)); struct spi_mem *spimem =3D spi_get_drvdata(spi); diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 63370c76394ee9b8d514da074779617cef67c311..73e44d724f90f4cd8fe8cafb9fa= 0c0fb23078e61 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -298,7 +298,8 @@ static umode_t nvmem_bin_attr_get_umode(struct nvmem_de= vice *nvmem) } =20 static umode_t nvmem_bin_attr_is_visible(struct kobject *kobj, - struct bin_attribute *attr, int i) + const struct bin_attribute *attr, + int i) { struct device *dev =3D kobj_to_dev(kobj); struct nvmem_device *nvmem =3D to_nvmem_device(dev); diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 040f01b2b999175e8d98b05851edc078bbabbe0d..13912940ed2bb66c0086e5bea9a= 3cb6417ac14dd 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1326,7 +1326,7 @@ static struct bin_attribute *pci_dev_rom_attrs[] =3D { }; =20 static umode_t pci_dev_rom_attr_is_visible(struct kobject *kobj, - struct bin_attribute *a, int n) + const struct bin_attribute *a, int n) { struct pci_dev *pdev =3D to_pci_dev(kobj_to_dev(kobj)); =20 diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index e4300f5f304f3ca55a657fd25a1fa5ed919737a7..a469bcbc0da7f7677485c7f999f= 8dfb58b8ae8a3 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -325,7 +325,7 @@ static struct bin_attribute *vpd_attrs[] =3D { }; =20 static umode_t vpd_attr_is_visible(struct kobject *kobj, - struct bin_attribute *a, int n) + const struct bin_attribute *a, int n) { struct pci_dev *pdev =3D to_pci_dev(kobj_to_dev(kobj)); =20 diff --git a/drivers/platform/x86/amd/hsmp.c b/drivers/platform/x86/amd/hsm= p.c index 8fcf38eed7f00ee01aade6e3e55e20402458d5aa..8f00850c139fa8d419bc1c140c1= 832bf84b2c3bd 100644 --- a/drivers/platform/x86/amd/hsmp.c +++ b/drivers/platform/x86/amd/hsmp.c @@ -620,7 +620,7 @@ static int hsmp_get_tbl_dram_base(u16 sock_ind) } =20 static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj, - struct bin_attribute *battr, int id) + const struct bin_attribute *battr, int id) { if (plat_dev.proto_ver =3D=3D HSMP_PROTO_VER6) return battr->attr.mode; diff --git a/drivers/platform/x86/intel/sdsi.c b/drivers/platform/x86/intel= /sdsi.c index 9d137621f0e6e7a23be0e0bbc6175c51c403169f..33f33b1070fdc949c1373251c3b= ca4234d9da119 100644 --- a/drivers/platform/x86/intel/sdsi.c +++ b/drivers/platform/x86/intel/sdsi.c @@ -541,7 +541,7 @@ static struct bin_attribute *sdsi_bin_attrs[] =3D { }; =20 static umode_t -sdsi_battr_is_visible(struct kobject *kobj, struct bin_attribute *attr, in= t n) +sdsi_battr_is_visible(struct kobject *kobj, const struct bin_attribute *at= tr, int n) { struct device *dev =3D kobj_to_dev(kobj); struct sdsi_priv *priv =3D dev_get_drvdata(dev); diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 32f94db6d6bf5d2bd289c1a121da7ffc6a7cb2ff..f3a1ecb42128a2b221ca5c362e0= 41eb59dba0f20 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -1274,7 +1274,7 @@ static umode_t scsi_sdev_attr_is_visible(struct kobje= ct *kobj, } =20 static umode_t scsi_sdev_bin_attr_is_visible(struct kobject *kobj, - struct bin_attribute *attr, int i) + const struct bin_attribute *attr, int i) { struct device *dev =3D kobj_to_dev(kobj); struct scsi_device *sdev =3D to_scsi_device(dev); diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index 61b6d978892c799e213018bed22d9fb12a19d429..b4cba23831acd2d7d395b9f7683= cd3ee3a8623c8 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c @@ -925,7 +925,7 @@ static struct bin_attribute *dev_bin_attrs[] =3D { }; =20 static umode_t dev_bin_attrs_are_visible(struct kobject *kobj, - struct bin_attribute *a, int n) + const struct bin_attribute *a, int n) { struct device *dev =3D kobj_to_dev(kobj); struct usb_device *udev =3D to_usb_device(dev); diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 4746cccb95898b24df6f53de9421ea7649b5568f..d1b22d56198b55ee39fe4c4fc99= 4f5b753641992 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -101,7 +101,7 @@ struct attribute_group { umode_t (*is_visible)(struct kobject *, struct attribute *, int); umode_t (*is_bin_visible)(struct kobject *, - struct bin_attribute *, int); + const struct bin_attribute *, int); size_t (*bin_size)(struct kobject *, const struct bin_attribute *, int); @@ -199,22 +199,22 @@ struct attribute_group { * attributes, the group visibility is determined by the function * specified to is_visible() not is_bin_visible() */ -#define DEFINE_SYSFS_BIN_GROUP_VISIBLE(name) \ - static inline umode_t sysfs_group_visible_##name( \ - struct kobject *kobj, struct bin_attribute *attr, int n) \ - { \ - if (n =3D=3D 0 && !name##_group_visible(kobj)) \ - return SYSFS_GROUP_INVISIBLE; \ - return name##_attr_visible(kobj, attr, n); \ +#define DEFINE_SYSFS_BIN_GROUP_VISIBLE(name) = \ + static inline umode_t sysfs_group_visible_##name( \ + struct kobject *kobj, const struct bin_attribute *attr, int n) \ + { \ + if (n =3D=3D 0 && !name##_group_visible(kobj)) \ + return SYSFS_GROUP_INVISIBLE; \ + return name##_attr_visible(kobj, attr, n); \ } =20 -#define DEFINE_SIMPLE_SYSFS_BIN_GROUP_VISIBLE(name) \ - static inline umode_t sysfs_group_visible_##name( \ - struct kobject *kobj, struct bin_attribute *a, int n) \ - { \ - if (n =3D=3D 0 && !name##_group_visible(kobj)) \ - return SYSFS_GROUP_INVISIBLE; \ - return a->mode; \ +#define DEFINE_SIMPLE_SYSFS_BIN_GROUP_VISIBLE(name) = \ + static inline umode_t sysfs_group_visible_##name( \ + struct kobject *kobj, const struct bin_attribute *a, int n) \ + { \ + if (n =3D=3D 0 && !name##_group_visible(kobj)) \ + return SYSFS_GROUP_INVISIBLE; \ + return a->mode; \ } =20 #define SYSFS_GROUP_VISIBLE(fn) sysfs_group_visible_##fn --=20 2.47.0 From nobody Mon Nov 25 01:55:40 2024 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 E77EF135A79 for ; Thu, 31 Oct 2024 02:44:29 +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=1730342672; cv=none; b=IdG7b3dwq3S4cmdPd+oHDbeJaBWQ94gwEr1dHiFZBBMl23E7CWrayHy5+0k80NmshEOJbVe4ltIar60dV0sahArVFrFbXLVIuUgC/uXy1JTHca47InPUuRO1n2M5j7oixlWFVePBwWPBkDEWlJmmU8Z4jiZCE3HHEJcSd9qS+7I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730342672; c=relaxed/simple; bh=G9vi/uBbOI72OcQYHh5qlCzGWOHssI8eKKs/SaJCZV8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JdOwF/k2rEADUULirkJVOaT/9JPHHIaW+ACw1uVF5HiXrzkSb1cCAHa9W62/ZAQaQvI7LYfzihWcJ2u7UzCEuIqpoGH9JnJaxenqu+o/nqsfLDr8cLG/5UpOkRUmMyptMggPwoY7zncOPwaIqXhkXMD8nbCaFg0bC+pwvdZKs9E= 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=ClujitPX; 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="ClujitPX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1730342665; bh=G9vi/uBbOI72OcQYHh5qlCzGWOHssI8eKKs/SaJCZV8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ClujitPXxLbHUO1PUByTCfoGFn89ghcIfl7WgXVeHvTyMsslCAB3WJQcUcn6skVoe aWyjRJTSDWBCYmZ1gQWDz5lf4eCKtp43tx73dxKAFZmrSTSOuosRWQSwR8uv3IOdvW OWmZG5qYcfV54ulpVhYOHnN8nAMH85/z+gUAxiqk= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 31 Oct 2024 02:43:55 +0000 Subject: [PATCH RFC 06/10] sysfs: treewide: constify attribute callback of bin_attribute::mmap() 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: <20241031-sysfs-const-bin_attr-v1-6-2281afa7f055@weissschuh.net> References: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> In-Reply-To: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Dan Williams , linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1730342657; l=5001; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=G9vi/uBbOI72OcQYHh5qlCzGWOHssI8eKKs/SaJCZV8=; b=qPnmCoKo88DEseAckSWRQYFHJLv962m74QL1AL8t625CLvay8P8mf/TYeqw3KPxIDJZcuisEr zHVYKIrmsBWAlrEXkL3QSUjyOnHkQzgHw0jYXS0dRkwZF+0xVYPFNWE X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The mmap() callbacks should not modify the struct bin_attribute passed as argument. Enforce this by marking the argument as const. As there are not many callback implementers perform this change throughout the tree at once. Signed-off-by: Thomas Wei=C3=9Fschuh --- drivers/misc/ocxl/sysfs.c | 2 +- drivers/pci/p2pdma.c | 2 +- drivers/pci/pci-sysfs.c | 6 +++--- drivers/platform/x86/intel/pmt/class.c | 2 +- drivers/uio/uio_hv_generic.c | 2 +- include/linux/sysfs.h | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/misc/ocxl/sysfs.c b/drivers/misc/ocxl/sysfs.c index 405180d47d9bff0aaa7a736bb3fecfbe318db961..07520d6e6dc55702696b8656440= 914c379e6e27a 100644 --- a/drivers/misc/ocxl/sysfs.c +++ b/drivers/misc/ocxl/sysfs.c @@ -125,7 +125,7 @@ static const struct vm_operations_struct global_mmio_vm= ops =3D { }; =20 static int global_mmio_mmap(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, struct vm_area_struct *vma) { struct ocxl_afu *afu =3D to_afu(kobj_to_dev(kobj)); diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c index 4f47a13cb500ff5339cde426b6ccb020fcd74ae7..7abd4f546d3c071f31e622d881f= 5c5ac3e4de55e 100644 --- a/drivers/pci/p2pdma.c +++ b/drivers/pci/p2pdma.c @@ -90,7 +90,7 @@ static ssize_t published_show(struct device *dev, struct = device_attribute *attr, static DEVICE_ATTR_RO(published); =20 static int p2pmem_alloc_mmap(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, struct vm_area_struct *vma) + const struct bin_attribute *attr, struct vm_area_struct *vma) { struct pci_dev *pdev =3D to_pci_dev(kobj_to_dev(kobj)); size_t len =3D vma->vm_end - vma->vm_start; diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 13912940ed2bb66c0086e5bea9a3cb6417ac14dd..36017fd1d4235d0a42fa91b47a3= c6de82d9af978 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1034,7 +1034,7 @@ void pci_remove_legacy_files(struct pci_bus *b) * * Use the regular PCI mapping routines to map a PCI resource into userspa= ce. */ -static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *a= ttr, +static int pci_mmap_resource(struct kobject *kobj, const struct bin_attrib= ute *attr, struct vm_area_struct *vma, int write_combine) { struct pci_dev *pdev =3D to_pci_dev(kobj_to_dev(kobj)); @@ -1059,14 +1059,14 @@ static int pci_mmap_resource(struct kobject *kobj, = struct bin_attribute *attr, } =20 static int pci_mmap_resource_uc(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, struct vm_area_struct *vma) { return pci_mmap_resource(kobj, attr, vma, 0); } =20 static int pci_mmap_resource_wc(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, struct vm_area_struct *vma) { return pci_mmap_resource(kobj, attr, vma, 1); diff --git a/drivers/platform/x86/intel/pmt/class.c b/drivers/platform/x86/= intel/pmt/class.c index c04bb7f97a4db13268fc5697887951cf8f0f5a25..f9afa23e754b8b68bd59b72d6a7= 2d26503a21f31 100644 --- a/drivers/platform/x86/intel/pmt/class.c +++ b/drivers/platform/x86/intel/pmt/class.c @@ -103,7 +103,7 @@ intel_pmt_read(struct file *filp, struct kobject *kobj, =20 static int intel_pmt_mmap(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, struct vm_area_struct *vma) + const struct bin_attribute *attr, struct vm_area_struct *vma) { struct intel_pmt_entry *entry =3D container_of(attr, struct intel_pmt_entry, diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c index 8704095994118c2660f345c504b5ea466d053efb..3976360d0096d6681faf88815cc= 6277fb76a1d9f 100644 --- a/drivers/uio/uio_hv_generic.c +++ b/drivers/uio/uio_hv_generic.c @@ -135,7 +135,7 @@ static void hv_uio_rescind(struct vmbus_channel *channe= l) * The ring buffer is allocated as contiguous memory by vmbus_open */ static int hv_uio_ring_mmap(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, + const struct bin_attribute *attr, struct vm_area_struct *vma) { struct vmbus_channel *channel diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index d1b22d56198b55ee39fe4c4fc994f5b753641992..9fcdc8cd3118f359742bfd8b708= d5c3eff511042 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -309,7 +309,7 @@ struct bin_attribute { char *, loff_t, size_t); loff_t (*llseek)(struct file *, struct kobject *, struct bin_attribute *, loff_t, int); - int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr, + int (*mmap)(struct file *, struct kobject *, const struct bin_attribute *= attr, struct vm_area_struct *vma); }; =20 --=20 2.47.0 From nobody Mon Nov 25 01:55:40 2024 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 B4D5C13B586 for ; Thu, 31 Oct 2024 02:44:31 +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=1730342673; cv=none; b=R+/JJTj/if3qVz4qUDN9gANvChgpuVXJRoeFtzTO3IIpO2h+P8sIyONlNeIhZUuFC3vQ/how/BsPy94GYapzO3lZbjpmwJSzgpBGZuIwOj19ytIs+fRE2XyswWb3rSa2P6C6uuX3hk0IdCx30u8+/1d6MxxYjGHtm1wLKK142no= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730342673; c=relaxed/simple; bh=T1BA7i5hh0VB3bv+J/Vp/hXtY5JBZ5VWww5X1VE5szM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=D5OneQjphYvFexzlF+r6Nnn2iXDg2ImpZWDsyB7tlBonVryJfC4TlNBSKgHUd6iw60DP/N9aNadVDfj0v7MFIB1/tWQmUceJuarI53Yv3brAfrVO5zzccqNXkgghBsIjI9A850PmP7BgPCGJJR961hMqLuLcPMI0MakuDHzGAIM= 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=IDH4HxRW; 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="IDH4HxRW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1730342669; bh=T1BA7i5hh0VB3bv+J/Vp/hXtY5JBZ5VWww5X1VE5szM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IDH4HxRWPL+3qnZ4RiYBMZEFS5WlyYl7Wno1oflObQwP92amMxAEk+0YIpj04xL04 +/tfefUYg28F0cp+4xvvwtT6qkwIx5ujFVgEYkC/Ru3iupmCt8UpoL/dXMmJ06GxZP N12s5YcwNnoQuY9tudgGnCDI/TXidfsy6qM2es64= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 31 Oct 2024 02:43:56 +0000 Subject: [PATCH RFC 07/10] sysfs: drop callback bin_attribute::llseek 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: <20241031-sysfs-const-bin_attr-v1-7-2281afa7f055@weissschuh.net> References: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> In-Reply-To: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Dan Williams , linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1730342657; l=1612; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=T1BA7i5hh0VB3bv+J/Vp/hXtY5JBZ5VWww5X1VE5szM=; b=3dln9Zw+Okjg5Zioa5YThSfXDcVFJh2zOMjYeAAdfxukctVYtITWxGJRFBV4s1zZJ1bUdcCyZ ZZejcuP82y4C7peLy9t/kyJJ0fO11L7LJz6PbYW/94bVNgq86BsxxiQ X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The callback is never implemented, drop it. Signed-off-by: Thomas Wei=C3=9Fschuh --- fs/sysfs/file.c | 8 +------- include/linux/sysfs.h | 2 -- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index 6d39696b43069010b0ad0bdaadcf9002cb70c92c..3515c172ec8ff70b87847d226a1= b3bc3b60826f9 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -170,13 +170,7 @@ static int sysfs_kf_bin_mmap(struct kernfs_open_file *= of, static loff_t sysfs_kf_bin_llseek(struct kernfs_open_file *of, loff_t offs= et, int whence) { - struct bin_attribute *battr =3D of->kn->priv; - struct kobject *kobj =3D of->kn->parent->priv; - - if (battr->llseek) - return battr->llseek(of->file, kobj, battr, offset, whence); - else - return generic_file_llseek(of->file, offset, whence); + return generic_file_llseek(of->file, offset, whence); } =20 static int sysfs_kf_bin_open(struct kernfs_open_file *of) diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 9fcdc8cd3118f359742bfd8b708d5c3eff511042..8344c0198c61cc44995c38d46d9= 26360e7a88873 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -307,8 +307,6 @@ struct bin_attribute { char *, loff_t, size_t); ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *, char *, loff_t, size_t); - loff_t (*llseek)(struct file *, struct kobject *, struct bin_attribute *, - loff_t, int); int (*mmap)(struct file *, struct kobject *, const struct bin_attribute *= attr, struct vm_area_struct *vma); }; --=20 2.47.0 From nobody Mon Nov 25 01:55:40 2024 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 B3ECC139D03 for ; Thu, 31 Oct 2024 02:44:30 +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=1730342672; cv=none; b=nSYdcaD8nAaP2XOiUgJsZQVbjrSj3htVc+Zhbzu0/+JWbUa+CxeU6u95Pj8mQ+w7/Zb602zHpDspWTolUB1F8FtJXrEhUxPKo6Ky6q8G8cGs7HMjhJzSo402MAivMhw1bA02tKDsgE/SBJY36Cu8sgQuPtpLXIy0gX3iINIU9Y4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730342672; c=relaxed/simple; bh=wfZdoH/QydBYPcdVBp6TI9VQV3Jcoh8nKlLLAo4iroo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=u51ZlBF/g6U48NkdRB1cgrJKomCEy3NpB5CW+Cn71Z9SaUzwuZm8AexSqHhUFisFJ5Mca/ycKVLlF2yIQuBLuhip9xiLLns9ENzrJ1o3h+R8WYzfTMgj3+x4+mYHIm4O3nRYJclt96Dff19etM6KfnZHfhmwiG9G+3MdvsaE5jo= 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=E4uEujSC; 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="E4uEujSC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1730342667; bh=wfZdoH/QydBYPcdVBp6TI9VQV3Jcoh8nKlLLAo4iroo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=E4uEujSCLXP4wbKL92QN9A5/RC1j+e2SA0TzeJrDMNjg63jpdBsEWfdtr0H4uqHCx xiFfpO/TKD8wXappxrvb2g+1m7cAereBdtvhEDB4cyEZxhuXxs7R6Ly58pCKhOHOQm 7iaYfRWm9b+7XhNWa+IOX/bHPzJjPaADqdse3JYE= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 31 Oct 2024 02:43:57 +0000 Subject: [PATCH RFC 08/10] sysfs: implement all BIN_ATTR_* macros in terms of __BIN_ATTR() 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: <20241031-sysfs-const-bin_attr-v1-8-2281afa7f055@weissschuh.net> References: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> In-Reply-To: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Dan Williams , linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1730342657; l=2547; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=wfZdoH/QydBYPcdVBp6TI9VQV3Jcoh8nKlLLAo4iroo=; b=7UCQtPZz/Vkgghxa8nmPrNqUyDomktlI3X1MKF63GdEAw5RWiUPjdKJ21Czsz/Q0qRhzO56vq 0lQuvRDBx4OAcH+FpWChL1qtmVvQiHI1fZMIeEhxK/SjKk+nFdeYI4i X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The preparations for the upcoming constification of struct bin_attribute requires some logic in the structure definition macros. To avoid duplication of that logic in multiple macros, reimplement all other macros in terms of __BIN_ATTR(). Signed-off-by: Thomas Wei=C3=9Fschuh --- include/linux/sysfs.h | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 8344c0198c61cc44995c38d46d926360e7a88873..5ece63c83ba5829b6eb0f115bde= a12a1412ae039 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -331,17 +331,11 @@ struct bin_attribute { .size =3D _size, \ } =20 -#define __BIN_ATTR_RO(_name, _size) { \ - .attr =3D { .name =3D __stringify(_name), .mode =3D 0444 }, \ - .read =3D _name##_read, \ - .size =3D _size, \ -} +#define __BIN_ATTR_RO(_name, _size) \ + __BIN_ATTR(_name, 0444, _name##_read, NULL, _size) =20 -#define __BIN_ATTR_WO(_name, _size) { \ - .attr =3D { .name =3D __stringify(_name), .mode =3D 0200 }, \ - .write =3D _name##_write, \ - .size =3D _size, \ -} +#define __BIN_ATTR_WO(_name, _size) \ + __BIN_ATTR(_name, 0200, NULL, _name##_write, _size) =20 #define __BIN_ATTR_RW(_name, _size) \ __BIN_ATTR(_name, 0644, _name##_read, _name##_write, _size) @@ -362,11 +356,8 @@ struct bin_attribute bin_attr_##_name =3D __BIN_ATTR_W= O(_name, _size) struct bin_attribute bin_attr_##_name =3D __BIN_ATTR_RW(_name, _size) =20 =20 -#define __BIN_ATTR_ADMIN_RO(_name, _size) { \ - .attr =3D { .name =3D __stringify(_name), .mode =3D 0400 }, \ - .read =3D _name##_read, \ - .size =3D _size, \ -} +#define __BIN_ATTR_ADMIN_RO(_name, _size) \ + __BIN_ATTR(_name, 0400, _name##_read, NULL, _size) =20 #define __BIN_ATTR_ADMIN_RW(_name, _size) \ __BIN_ATTR(_name, 0600, _name##_read, _name##_write, _size) @@ -377,10 +368,8 @@ struct bin_attribute bin_attr_##_name =3D __BIN_ATTR_A= DMIN_RO(_name, _size) #define BIN_ATTR_ADMIN_RW(_name, _size) \ struct bin_attribute bin_attr_##_name =3D __BIN_ATTR_ADMIN_RW(_name, _size) =20 -#define __BIN_ATTR_SIMPLE_RO(_name, _mode) { \ - .attr =3D { .name =3D __stringify(_name), .mode =3D _mode }, \ - .read =3D sysfs_bin_attr_simple_read, \ -} +#define __BIN_ATTR_SIMPLE_RO(_name, _mode) \ + __BIN_ATTR(_name, _mode, sysfs_bin_attr_simple_read, NULL, 0) =20 #define BIN_ATTR_SIMPLE_RO(_name) \ struct bin_attribute bin_attr_##_name =3D __BIN_ATTR_SIMPLE_RO(_name, 0444) --=20 2.47.0 From nobody Mon Nov 25 01:55:40 2024 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 9029C13C9C0 for ; Thu, 31 Oct 2024 02:44:32 +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=1730342674; cv=none; b=CYNnNoWXlilB5/qDNvFLov8//UoYiKQEjA0VQ5yIoq8V1RZk2EFYBkeK0PQFs2YwUC9K29T5Px0pBCyzDnV8mW5GAZuKxhTd6HO28mL2b0EtvmcZiX2/7r3SwpY+RAGRt/DO1RF1wEZN5hHKR2n3oYH8mX6kmohF0XzMFhesfLQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730342674; c=relaxed/simple; bh=oL8Kp9Zy302HGyHPYfss16ykvbWIdf2BUzXuS9J1tY4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DODF8jhZjqmlPjQ79w7BCPcOVk8piuB+NkOAceTeuYGmYQuqtDNM5lMwqvwvPh+uCLQj6LA3PnYQoxDxotg0z5EEvv5kEfpCn73hpNw/Gw78SHGb+cGT+E1imam0OEgibYrVx49UNvFNBhuMcJQiDqkWVEC9jTuNfB1vUI+y298= 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=QM1O/uH8; 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="QM1O/uH8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1730342670; bh=oL8Kp9Zy302HGyHPYfss16ykvbWIdf2BUzXuS9J1tY4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QM1O/uH80bioL45UeRTBIQxfPBaVT14107nyKAlmZ//FiCCl1PWa+qZrnbZnk1VGh PQojZSy/guUQ/LB0NEfNNU5W77tnNqReTOcDwHUwBRYQqQfmThqwaMa1gsW9u65hcl DMTGS79r5uqi9Z9EWGPcbi9utL7E08rkHRWGLcQo= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 31 Oct 2024 02:43:58 +0000 Subject: [PATCH RFC 09/10] sysfs: bin_attribute: add const read/write callback variants 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: <20241031-sysfs-const-bin_attr-v1-9-2281afa7f055@weissschuh.net> References: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> In-Reply-To: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Dan Williams , linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1730342657; l=4665; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=oL8Kp9Zy302HGyHPYfss16ykvbWIdf2BUzXuS9J1tY4=; b=8CA5QG4cEMCokmQetltBwJND1XMM/NIPB0ZHqAwc3GbqGDdIR/RrddTTG+IZPi1ovkNFt5Jyd Vd7WxvlDFORDhlPVtpulQM5v8eEYdVN4ckfleobNKqxmEiJdkzSKofe X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= To make it possible to put struct bin_attribute into read-only memory, the sysfs core has to stop passing mutable pointers to the read() and write() callbacks. As there are numerous implementors of these callbacks throughout the tree it's not possible to change all of them at once. To enable a step-by-step transition, add new variants of the read() and write() callbacks which differ only in the constness of the struct bin_attribute argument. As most binary attributes are defined through macros, extend these macros to transparently handle both variants of callbacks to minimize the churn during the transition. As soon as all handlers are switch to the const variant, the non-const one can be removed together with the transition machinery. Signed-off-by: Thomas Wei=C3=9Fschuh --- fs/sysfs/file.c | 16 +++++++++++----- include/linux/sysfs.h | 31 +++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index 3515c172ec8ff70b87847d226a1b3bc3b60826f9..58a98b4dc9b28dab9e36c831581= 608eaf6f95848 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -91,9 +91,12 @@ static ssize_t sysfs_kf_bin_read(struct kernfs_open_file= *of, char *buf, count =3D size - pos; } =20 - if (!battr->read) + if (!battr->read && !battr->read_new) return -EIO; =20 + if (battr->read_new) + return battr->read_new(of->file, kobj, battr, buf, pos, count); + return battr->read(of->file, kobj, battr, buf, pos, count); } =20 @@ -152,9 +155,12 @@ static ssize_t sysfs_kf_bin_write(struct kernfs_open_f= ile *of, char *buf, if (!count) return 0; =20 - if (!battr->write) + if (!battr->write && !battr->write_new) return -EIO; =20 + if (battr->write_new) + return battr->write_new(of->file, kobj, battr, buf, pos, count); + return battr->write(of->file, kobj, battr, buf, pos, count); } =20 @@ -319,11 +325,11 @@ int sysfs_add_bin_file_mode_ns(struct kernfs_node *pa= rent, =20 if (battr->mmap) ops =3D &sysfs_bin_kfops_mmap; - else if (battr->read && battr->write) + else if ((battr->read || battr->read_new) && (battr->write || battr->writ= e_new)) ops =3D &sysfs_bin_kfops_rw; - else if (battr->read) + else if (battr->read || battr->read_new) ops =3D &sysfs_bin_kfops_ro; - else if (battr->write) + else if (battr->write || battr->write_new) ops =3D &sysfs_bin_kfops_wo; else ops =3D &sysfs_file_kfops_empty; diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 5ece63c83ba5829b6eb0f115bdea12a1412ae039..34e94e75231166839452b89aa11= 14d90657257d1 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -305,8 +305,12 @@ struct bin_attribute { struct address_space *(*f_mapping)(void); ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *, char *, loff_t, size_t); + ssize_t (*read_new)(struct file *, struct kobject *, const struct bin_att= ribute *, + char *, loff_t, size_t); ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *, char *, loff_t, size_t); + ssize_t (*write_new)(struct file *, struct kobject *, + const struct bin_attribute *, char *, loff_t, size_t); int (*mmap)(struct file *, struct kobject *, const struct bin_attribute *= attr, struct vm_area_struct *vma); }; @@ -323,11 +327,34 @@ struct bin_attribute { */ #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr) =20 +typedef ssize_t __sysfs_rw_handler(struct file *, struct kobject *, + struct bin_attribute *, char *, loff_t, size_t); +typedef ssize_t __sysfs_rw_handler_new(struct file *, struct kobject *, + const struct bin_attribute *, char *, loff_t, size_t); + /* macros to create static binary attributes easier */ #define __BIN_ATTR(_name, _mode, _read, _write, _size) { \ .attr =3D { .name =3D __stringify(_name), .mode =3D _mode }, \ - .read =3D _read, \ - .write =3D _write, \ + .read =3D _Generic(_read, \ + __sysfs_rw_handler * : _read, \ + __sysfs_rw_handler_new * : NULL, \ + void * : NULL \ + ), \ + .read_new =3D _Generic(_read, \ + __sysfs_rw_handler * : NULL, \ + __sysfs_rw_handler_new * : _read, \ + void * : NULL \ + ), \ + .write =3D _Generic(_write, \ + __sysfs_rw_handler * : _write, \ + __sysfs_rw_handler_new * : NULL, \ + void * : NULL \ + ), \ + .write_new =3D _Generic(_write, \ + __sysfs_rw_handler * : NULL, \ + __sysfs_rw_handler_new * : _write, \ + void * : NULL \ + ), \ .size =3D _size, \ } =20 --=20 2.47.0 From nobody Mon Nov 25 01:55:40 2024 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 2C17C13BC35 for ; Thu, 31 Oct 2024 02:44:32 +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=1730342674; cv=none; b=kUWUFUkuFV92ZtV11D0HEighJDkbxNA+HMCXBf2EZ8sKlnYVyRLZiWHk6SNWVmqnI4akA1DmTXS6N60QFe7gZZijNWbcoiTiidBiTlOPF+VsADtAtMz3LphSStMu5dmUNvRiZSJBX4KTCAkLanYwK3NiL3Qz8HHtGlesDsXMdLY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730342674; c=relaxed/simple; bh=i1lGRcvBSYaAkRCU3PsefBTXEi2eEGtd/RNZhauMerg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bl1DheUSFIzGu+1DpeQVS9REYaK/rJRBWWl14x7xHOG3iwsWJSDLT2jFAx77Q6gyRbyhC+nUkPhlSp1NzfYu6aDVJtxdc6776GvEHseSOuRsP/892+LIaKQpw+Botgk9m9EdF6pzmvhbSDshgxVvNgO/0D76J6PjEJBzblntprw= 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=SgdNzxzM; 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="SgdNzxzM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1730342670; bh=i1lGRcvBSYaAkRCU3PsefBTXEi2eEGtd/RNZhauMerg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SgdNzxzMiYxflEhxc4zZ09ihbZA0Xs2225NkbF5pZFnIUf6zhqMmCw0y94cdP+Rfg 8stulYcDDZzZ6yvYlt6ekhF7OXpCEwQk/wvM5UefSoE5UJcNEhyHCQwIC28lKkr9/0 sg2slJ0Wa+2Gwe64V/H6pGeBFkj4F8mhLC7QeAwM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 31 Oct 2024 02:43:59 +0000 Subject: [PATCH RFC 10/10] driver core: Constify attribute arguments of binary 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: <20241031-sysfs-const-bin_attr-v1-10-2281afa7f055@weissschuh.net> References: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> In-Reply-To: <20241031-sysfs-const-bin_attr-v1-0-2281afa7f055@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: Dan Williams , linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1730342657; l=2330; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=i1lGRcvBSYaAkRCU3PsefBTXEi2eEGtd/RNZhauMerg=; b=470iQ9NDnuAKYE5QZCLHTilcvwmKlMlL3K95787QwTdoOu7rrtFzqJc1H1XZ+6Ukm+sMLYlEM cGiOY/0k5uOD5ZbaiCW/Jc5e6bVwcLqd5EdM71cU/F33tQJFOvCOLrI X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= As preparation for the constification of struct bin_attribute, constify the arguments of the read and write callbacks. Signed-off-by: Thomas Wei=C3=9Fschuh --- drivers/base/node.c | 4 ++-- drivers/base/topology.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/base/node.c b/drivers/base/node.c index eb72580288e62727e5b2198a6451cf9c2533225a..3e761633ac75826bedb5dd30b87= 9f7cc1af95ec3 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -27,7 +27,7 @@ static const struct bus_type node_subsys =3D { }; =20 static inline ssize_t cpumap_read(struct file *file, struct kobject *kobj, - struct bin_attribute *attr, char *buf, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct device *dev =3D kobj_to_dev(kobj); @@ -48,7 +48,7 @@ static inline ssize_t cpumap_read(struct file *file, stru= ct kobject *kobj, static BIN_ATTR_RO(cpumap, CPUMAP_FILE_MAX_BYTES); =20 static inline ssize_t cpulist_read(struct file *file, struct kobject *kobj, - struct bin_attribute *attr, char *buf, + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { struct device *dev =3D kobj_to_dev(kobj); diff --git a/drivers/base/topology.c b/drivers/base/topology.c index 89f98be5c5b9915b2974e184bf89c4c25c183095..1090751d7f458ce8d2a50e82d65= b8ce31e938f15 100644 --- a/drivers/base/topology.c +++ b/drivers/base/topology.c @@ -23,7 +23,7 @@ static ssize_t name##_show(struct device *dev, \ =20 #define define_siblings_read_func(name, mask) \ static ssize_t name##_read(struct file *file, struct kobject *kobj, \ - struct bin_attribute *attr, char *buf, \ + const struct bin_attribute *attr, char *buf, \ loff_t off, size_t count) \ { \ struct device *dev =3D kobj_to_dev(kobj); = \ @@ -33,7 +33,7 @@ static ssize_t name##_read(struct file *file, struct kobj= ect *kobj, \ } \ \ static ssize_t name##_list_read(struct file *file, struct kobject *kobj, \ - struct bin_attribute *attr, char *buf, \ + const struct bin_attribute *attr, char *buf, \ loff_t off, size_t count) \ { \ struct device *dev =3D kobj_to_dev(kobj); \ --=20 2.47.0