From patchwork Sun Dec 15 14:49:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13908785 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 84152A47 for ; Sun, 15 Dec 2024 14:49:16 +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=1734274160; cv=none; b=WVexCaW/ODE7STBsuXGenhmXhtTzyO71vJgXUq1DdiY9PAObXuBtn1xG+13L9TCAZoBV/9ijjhIZLi9QLaAtKoTLTICY8MwqL48djwdVaK/Rivql3h8NcGBfrrJsxZ56u0sLEVn0tn26/FOe9IyMFxZgcUMq/YCDU5ZRMRZo6eA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734274160; c=relaxed/simple; bh=BOpBAV2k4jTrjMyus8d4jUCKCV1/z/2Q5Zkgqy8lyX8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pelqPTGa2iGsZbftW1mi3kkRgohr4zWlx+zvKWRGRtnCQGK8UmLdrpJLWL8imSA9oB3bl7okijnU/qD/BbsjIlN6F7rQj/OBCPHXboZKYjtMY9tMPtET2RLmB4LibtQ/GNAcCPr6hW6EAdsW3F9mgbZupUMKQQn58RbFRv+1ucE= 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=IqgtwNum; 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="IqgtwNum" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734274154; bh=BOpBAV2k4jTrjMyus8d4jUCKCV1/z/2Q5Zkgqy8lyX8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IqgtwNumuDG6hu6iAXyqGtVi4UezcQqgWPszbQmzZzDKAcuat9abCB2fLs20b+00d gCFhlEYZd8QKP9JpG3lf/nk62dP5MtMfq615pcmH6M6NNrwZhQ4vrMsE96szUH9kEG JxIDX9O5e2jJuhlPYUQs3jK4ik57vwmnlWXnX6/g= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 15 Dec 2024 15:49:09 +0100 Subject: [PATCH 1/4] firmware: google: cbmem: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241215-sysfs-const-bin_attr-google-v1-1-e5c2808f5833@weissschuh.net> References: <20241215-sysfs-const-bin_attr-google-v1-0-e5c2808f5833@weissschuh.net> In-Reply-To: <20241215-sysfs-const-bin_attr-google-v1-0-e5c2808f5833@weissschuh.net> To: Tzung-Bi Shih , Brian Norris , Julius Werner Cc: chrome-platform@lists.linux.dev, 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=1734274153; l=2094; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=BOpBAV2k4jTrjMyus8d4jUCKCV1/z/2Q5Zkgqy8lyX8=; b=EH8oiUeEjnDvdJqmUlSU2D4BtirI9kbHItut16hk9OkQC5wyFv/tUL4QVNdQUMGm1biH89wKW wZib3mqc3sQC3VM+39+CUqy2w7aUp2au7494DIm8pMuFTBiUauxDKCK X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The sysfs core now allows instances of 'struct bin_attribute' to be moved into read-only memory. Make use of that to protect them against accidental or malicious modifications. Signed-off-by: Thomas Weißschuh --- drivers/firmware/google/cbmem.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/google/cbmem.c b/drivers/firmware/google/cbmem.c index 66042160b361fe2a2d9599880a96d5de14b7128d..773d05078e0ae0763591a6d9cfa0d55ea5fff611 100644 --- a/drivers/firmware/google/cbmem.c +++ b/drivers/firmware/google/cbmem.c @@ -30,7 +30,7 @@ static struct cbmem_entry *to_cbmem_entry(struct kobject *kobj) } static ssize_t mem_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, char *buf, loff_t pos, + const struct bin_attribute *bin_attr, char *buf, loff_t pos, size_t count) { struct cbmem_entry *entry = to_cbmem_entry(kobj); @@ -40,7 +40,7 @@ static ssize_t mem_read(struct file *filp, struct kobject *kobj, } static ssize_t mem_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, char *buf, loff_t pos, + const struct bin_attribute *bin_attr, char *buf, loff_t pos, size_t count) { struct cbmem_entry *entry = to_cbmem_entry(kobj); @@ -53,7 +53,7 @@ static ssize_t mem_write(struct file *filp, struct kobject *kobj, memcpy(entry->mem_file_buf + pos, buf, count); return count; } -static BIN_ATTR_ADMIN_RW(mem, 0); +static const BIN_ATTR_ADMIN_RW(mem, 0); static ssize_t address_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -79,14 +79,14 @@ static struct attribute *attrs[] = { NULL, }; -static struct bin_attribute *bin_attrs[] = { +static const struct bin_attribute *const bin_attrs[] = { &bin_attr_mem, NULL, }; static const struct attribute_group cbmem_entry_group = { .attrs = attrs, - .bin_attrs = bin_attrs, + .bin_attrs_new = bin_attrs, }; static const struct attribute_group *dev_groups[] = { From patchwork Sun Dec 15 14:49:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13908782 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 6B66118D63C for ; Sun, 15 Dec 2024 14:49:17 +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=1734274159; cv=none; b=t+ZNwq/ieKl/dyQE8a4BA5HNzO60Mazf5zb9k23Z6e+0hlQYTNjBEQsAX8yRTbwuZMXrj44SbFwX1J2BGRrQrs4i1pypKtOrHrqtviII6y7xjqrWWikH5vG9M/SsMSHdM4LMDRi1ICDRJfxNpCa09s5WXU1ikVjy6gekuwMCFnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734274159; c=relaxed/simple; bh=OD/lWja0joVP9SVburnkmOGS1hQtirbqWB+jWss8JFI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DdNxD2ZU5+tKILPBK1NkjtYBMIwU3a7Z6azYTm8ojAi/tswZVH49HAduzrUuxDYYhXwtVHrVH+1Y8U90q1C+WfmfSFSukemplic2dVVbcK7pEWMP1C+vFGVK4vvzrjeWSJIW4JTDNbSOU7VbLd1z1TWeUmCn5pwqerVa3WMKVew= 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=eWO3aJxh; 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="eWO3aJxh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734274154; bh=OD/lWja0joVP9SVburnkmOGS1hQtirbqWB+jWss8JFI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=eWO3aJxhDiFpDpZ7akFcpN4b6hIZ1NSOM5B9SaMNeEk/xFyHqqGvg0eTRfxZQaN5j R7h0H1q/bGqkMu5Q3nVSAxZYspFMmTcm4NfVDSnGVRtckHi7T14dgXh1yBy3K8ts0N /qs+tBA7XEq6G5ttrL0wktU7451yhQLDnJKebcgw= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 15 Dec 2024 15:49:10 +0100 Subject: [PATCH 2/4] firmware: google: gsmi: Constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241215-sysfs-const-bin_attr-google-v1-2-e5c2808f5833@weissschuh.net> References: <20241215-sysfs-const-bin_attr-google-v1-0-e5c2808f5833@weissschuh.net> In-Reply-To: <20241215-sysfs-const-bin_attr-google-v1-0-e5c2808f5833@weissschuh.net> To: Tzung-Bi Shih , Brian Norris , Julius Werner Cc: chrome-platform@lists.linux.dev, 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=1734274153; l=1375; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=OD/lWja0joVP9SVburnkmOGS1hQtirbqWB+jWss8JFI=; b=zoty251LisZOy9nkLs5RVC6Mdj1bppEadFFAktrMHWMQjivkuIrddKYlBft+ziH7xs15NyFr4 oSrUsxQqMavA2cs+mZtwNc6Edz2U9UR/vI3/qyuaD80ezUQF1ZUtphJ X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The sysfs core now allows instances of 'struct bin_attribute' to be moved into read-only memory. Make use of that to protect them against accidental or malicious modifications. Signed-off-by: Thomas Weißschuh --- drivers/firmware/google/gsmi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/google/gsmi.c b/drivers/firmware/google/gsmi.c index 24e666d5c3d1a231d611ad3c20816c1d223a0dc5..e8fb00dcaf65bc593dd15562f20aeea482ccfc3e 100644 --- a/drivers/firmware/google/gsmi.c +++ b/drivers/firmware/google/gsmi.c @@ -488,7 +488,7 @@ static const struct efivar_operations efivar_ops = { #endif /* CONFIG_EFI */ static ssize_t eventlog_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t pos, size_t count) { struct gsmi_set_eventlog_param param = { @@ -528,9 +528,9 @@ static ssize_t eventlog_write(struct file *filp, struct kobject *kobj, } -static struct bin_attribute eventlog_bin_attr = { +static const struct bin_attribute eventlog_bin_attr = { .attr = {.name = "append_to_eventlog", .mode = 0200}, - .write = eventlog_write, + .write_new = eventlog_write, }; static ssize_t gsmi_clear_eventlog_store(struct kobject *kobj, From patchwork Sun Dec 15 14:49:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13908783 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 7AA6918E373 for ; Sun, 15 Dec 2024 14:49:17 +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=1734274159; cv=none; b=UKRE84DudHltlObjP4xNSbJzlyg8j7A9ZlYDybiYYEBCTNrkCZxghVFvXWC8E+jYSJr4opD4la+/yFWs10G4HtuLno8FgO+bZZt/7c4yGsxBQJM/kpHm/DiWLWmhJHaEVj+FHnO09eDqfmQJBTovytF2r8hwSSqVzwZMoPFmx1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734274159; c=relaxed/simple; bh=GPoO2MlSyFN41keL/IQMHVzwngO96d3fyeoIVD73xh0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TuNPQouPX2vo+zURuO33YWwisledZEsrw0YZkxUQ54qBmWrVUw7xMEE/rhw3wjEo3/OGjRDs3dU68zUxoYtVCUhIG5YxIITjE6G6A0iPxMvNhzXynr7KG/6eaEhGXbGzD6tCmLeRBru8tqfhADKwS4e56Ql9IVdVuq6PhGZCNF0= 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=kqrI1soz; 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="kqrI1soz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734274154; bh=GPoO2MlSyFN41keL/IQMHVzwngO96d3fyeoIVD73xh0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kqrI1sozDNK2AvehZaV6vrnPcQnHjIX63VWtGVuX5PrnIRydf37SmfuXcC50KMzU1 VrO/QF2HovWq9imz0jt17WDBYaJK57fGEVwE6WfRYegxu1J9N1cgqt8l0KGfGkzMmK IEbkdHc9pulhDogINALIBHxIPlhnl3aAAVr/mq/Q= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 15 Dec 2024 15:49:11 +0100 Subject: [PATCH 3/4] firmware: google: memconsole: Use const 'struct bin_attribute' callback Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241215-sysfs-const-bin_attr-google-v1-3-e5c2808f5833@weissschuh.net> References: <20241215-sysfs-const-bin_attr-google-v1-0-e5c2808f5833@weissschuh.net> In-Reply-To: <20241215-sysfs-const-bin_attr-google-v1-0-e5c2808f5833@weissschuh.net> To: Tzung-Bi Shih , Brian Norris , Julius Werner Cc: chrome-platform@lists.linux.dev, 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=1734274153; l=1259; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=GPoO2MlSyFN41keL/IQMHVzwngO96d3fyeoIVD73xh0=; b=Rj/FM7RcVBGvm/gpxe+tx2rQ8WNOo+HWXEO2lIlSCw+4yndXGxNqd5yMUrbhhDpFa6SHj113J OUzVm/WZIkxAnOxLJaqIotYuRPnqD/evAmeLx2kACKW6uwd42u+0gul X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The sysfs core now provides callback variants that explicitly take a const pointer. Use them so the non-const variants can be removed. Signed-off-by: Thomas Weißschuh --- drivers/firmware/google/memconsole.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c index b9d99fe1ff0f683f9fff3c4bc669d2a85c703366..d957af6f934984b74627e83f458575dbf2b7d592 100644 --- a/drivers/firmware/google/memconsole.c +++ b/drivers/firmware/google/memconsole.c @@ -14,7 +14,7 @@ #include "memconsole.h" static ssize_t memconsole_read(struct file *filp, struct kobject *kobp, - struct bin_attribute *bin_attr, char *buf, + const struct bin_attribute *bin_attr, char *buf, loff_t pos, size_t count) { ssize_t (*memconsole_read_func)(char *, loff_t, size_t); @@ -28,7 +28,7 @@ static ssize_t memconsole_read(struct file *filp, struct kobject *kobp, static struct bin_attribute memconsole_bin_attr = { .attr = {.name = "log", .mode = 0444}, - .read = memconsole_read, + .read_new = memconsole_read, }; void memconsole_setup(ssize_t (*read_func)(char *, loff_t, size_t)) From patchwork Sun Dec 15 14:49:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13908784 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 7A9B618DF62 for ; Sun, 15 Dec 2024 14:49:17 +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=1734274159; cv=none; b=qGDEBit4YVE9TId4ZeSuH+MrDAIdnn9ms50vBZEWnMYfCmDF3WywJa/rRvT1YBIbK1QZoT9uQQRDsp2zBQbBf92OBI0I3vsMuDXtntZMxJCFp9Gky4q2bXKUGZ1/ODLbN0YXnaZ2CHQfhgJpiT2E7zmzEdhLA2xQoO9yrcMJR0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734274159; c=relaxed/simple; bh=WLLl0SXp2QxmvD1/OoHCr/gA5uXOCZ9Y2YGLQhVDl4s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aiGeAAiDEDorStgnmOdt8y0Yq/eTtRgRPd9v6mZMPn9Xsv54YjWMHVsHkwZtnXsDx4fGRhBlmPWPhN4cxwxIh5uZli6sejKXAWN0p5st3x1Pu4WWAoqHq5fp9JnGMq2OmiYuSQEodMyY4f90ELejjAcNRcWwGiGAXMOnraha7bY= 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=dS6BGN6d; 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="dS6BGN6d" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1734274154; bh=WLLl0SXp2QxmvD1/OoHCr/gA5uXOCZ9Y2YGLQhVDl4s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dS6BGN6d3DlsD5DTIEYhmwPuix1uiCp8OSaRbOgXHat0v9chIV4ZFUfz/jEfsM04B S1SVKDnAenBUee1bZ3nk59i5IqGo4TB9gtMMrfoZ+b+ZdptUKvbFbo0mDOTdKdAJCU gO4ShP8n5Hbpf+EnKAHiNoIiAoYsCtFks49DGQCQ= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 15 Dec 2024 15:49:12 +0100 Subject: [PATCH 4/4] firmware: google: vpd: Use const 'struct bin_attribute' callback Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241215-sysfs-const-bin_attr-google-v1-4-e5c2808f5833@weissschuh.net> References: <20241215-sysfs-const-bin_attr-google-v1-0-e5c2808f5833@weissschuh.net> In-Reply-To: <20241215-sysfs-const-bin_attr-google-v1-0-e5c2808f5833@weissschuh.net> To: Tzung-Bi Shih , Brian Norris , Julius Werner Cc: chrome-platform@lists.linux.dev, 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=1734274153; l=3481; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=WLLl0SXp2QxmvD1/OoHCr/gA5uXOCZ9Y2YGLQhVDl4s=; b=JnFxNi5bWLzCfBERDYtH86MY5DNmcQ9bY8COJI+GLalpI7cZQmFWf8FjrDl03KEuxUiLc4uvT TWrSRh5uiYbD/QL8mUOJOJz09vNs03PnzF70MIFJvYM3gcyWao/j7Ri X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The sysfs core now provides callback variants that explicitly take a const pointer. Use them so the non-const variants can be removed. Signed-off-by: Thomas Weißschuh --- The custom read functions could also just be replaced by sysfs_bin_attr_simple_read(). See below. That would slightly conflict with another series of mine [0], bute the resolution would be trivial. [0] https://lore.kernel.org/lkml/20241205-sysfs-const-bin_attr-simple-v1-0-4a4e4ced71e3@weissschuh.net/ diff --git a/drivers/firmware/google/vpd.c b/drivers/firmware/google/vpd.c index 254ac6545d68..1ce9a7af635e 100644 --- a/drivers/firmware/google/vpd.c +++ b/drivers/firmware/google/vpd.c @@ -121,8 +111,8 @@ static int vpd_section_attrib_add(const u8 *key, u32 key_len, info->bin_attr.attr.name = info->key; info->bin_attr.attr.mode = 0444; info->bin_attr.size = value_len; - info->bin_attr.read_new = vpd_attrib_read; - info->bin_attr.private = info; + info->bin_attr.read = sysfs_bin_attr_simple_read; + info->bin_attr.private = (void *)info->value; info->value = value; static int vpd_section_create_attribs(struct vpd_section *sec) { s32 consumed; @@ -201,8 +181,8 @@ static int vpd_section_init(const char *name, struct vpd_section *sec, sec->bin_attr.attr.name = sec->raw_name; sec->bin_attr.attr.mode = 0444; sec->bin_attr.size = size; - sec->bin_attr.read_new = vpd_section_read; - sec->bin_attr.private = sec; + sec->bin_attr.read = sysfs_bin_attr_simple_read; + sec->bin_attr.private = sec->baseaddr; err = sysfs_create_bin_file(vpd_kobj, &sec->bin_attr); if (err) --- drivers/firmware/google/vpd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/google/vpd.c b/drivers/firmware/google/vpd.c index 1749529f63d449dd88e90e12ac6e50ad8f15450d..254ac6545d680ac099ae2efa3c2109c9eb8c41be 100644 --- a/drivers/firmware/google/vpd.c +++ b/drivers/firmware/google/vpd.c @@ -56,7 +56,7 @@ static struct vpd_section ro_vpd; static struct vpd_section rw_vpd; static ssize_t vpd_attrib_read(struct file *filp, struct kobject *kobp, - struct bin_attribute *bin_attr, char *buf, + const struct bin_attribute *bin_attr, char *buf, loff_t pos, size_t count) { struct vpd_attrib_info *info = bin_attr->private; @@ -121,7 +121,7 @@ static int vpd_section_attrib_add(const u8 *key, u32 key_len, info->bin_attr.attr.name = info->key; info->bin_attr.attr.mode = 0444; info->bin_attr.size = value_len; - info->bin_attr.read = vpd_attrib_read; + info->bin_attr.read_new = vpd_attrib_read; info->bin_attr.private = info; info->value = value; @@ -156,7 +156,7 @@ static void vpd_section_attrib_destroy(struct vpd_section *sec) } static ssize_t vpd_section_read(struct file *filp, struct kobject *kobp, - struct bin_attribute *bin_attr, char *buf, + const struct bin_attribute *bin_attr, char *buf, loff_t pos, size_t count) { struct vpd_section *sec = bin_attr->private; @@ -201,7 +201,7 @@ static int vpd_section_init(const char *name, struct vpd_section *sec, sec->bin_attr.attr.name = sec->raw_name; sec->bin_attr.attr.mode = 0444; sec->bin_attr.size = size; - sec->bin_attr.read = vpd_section_read; + sec->bin_attr.read_new = vpd_section_read; sec->bin_attr.private = sec; err = sysfs_create_bin_file(vpd_kobj, &sec->bin_attr);