From patchwork Mon Dec 2 19:02:19 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: 846841 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 1D19D1DE3D8; Mon, 2 Dec 2024 19:02:20 +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=1733166142; cv=none; b=OW6gExTtesXTRMQ/lEVk+Tbs6Ulj+4GnYhvkFMNs+V1+s84D2Ihy+GKCzLdN1YexEgtMLm10m3BcQsLsq8yO2W4h95SGTaIFCuYkAr8k+cVQFKhO9dcueMYtzZmfl76EzgqWg7LLpPhLiTSq61mTV7C+EbZcQnmiBWSeR5PSOOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733166142; c=relaxed/simple; bh=vs237hxNCHuIOeDxAr5dea8fYVyVtnREj4eNa7u5ziw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gSxN51j6/v7x8J+hD0GFaF+dejI3j0kDgkV8U4wxw4K7xKCRASupIntLoaE0jkg2JDsUxJ6x33SJqXXIxMnAowkIIxmHJwOTiu+rR0zds2VQ3CehQsWSIdnVx8XXpPqrXXFIYxg4r5B5aRwGpWJD1defUevFNm5byMVgryng+8U= 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=HJHQ1cOp; 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="HJHQ1cOp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733166139; bh=vs237hxNCHuIOeDxAr5dea8fYVyVtnREj4eNa7u5ziw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HJHQ1cOpqRRHj15C7dTKRxiEUyRQZHPeMmL/iv77nBqIrW85va1896BUPBl3BAtwx 7xB0u8iQLrosdpZfcR+9yPCJxxcEBgtW4kOpy3YzxlLWhdCsFmrJbES2UPs941Ny14 0tk3FwG2dSs3alUIIOqQn6PAukYk/0+B35dRQ0po= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 02 Dec 2024 20:02:19 +0100 Subject: [PATCH 1/4] power: supply: ds2760: constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241202-sysfs-const-bin_attr-psy-v1-1-f846430b8b66@weissschuh.net> References: <20241202-sysfs-const-bin_attr-psy-v1-0-f846430b8b66@weissschuh.net> In-Reply-To: <20241202-sysfs-const-bin_attr-psy-v1-0-f846430b8b66@weissschuh.net> To: Sebastian Reichel Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas?= =?utf-8?q?_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733166139; l=1541; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=vs237hxNCHuIOeDxAr5dea8fYVyVtnREj4eNa7u5ziw=; b=FhfmEOx2XZpc+pfW3LjqcL+yoz3Mx/qIIYNe/k5GfKMq8H2PePGstWivVaV3cFEviHhaNwmjj wWAdeU3tiajAPSd9hjumOWZ96TrbZSM/Jueebh6w8p0sp59IarFqctx 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/power/supply/ds2760_battery.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/power/supply/ds2760_battery.c b/drivers/power/supply/ds2760_battery.c index 7cf4ea06b5003427ac9719043c9a5a4361cb5341..83bdec5a2bda901460e0a8618949baa7ecc11e46 100644 --- a/drivers/power/supply/ds2760_battery.c +++ b/drivers/power/supply/ds2760_battery.c @@ -195,22 +195,22 @@ static int w1_ds2760_recall_eeprom(struct device *dev, int addr) } static ssize_t w1_slave_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, char *buf, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct device *dev = kobj_to_dev(kobj); return w1_ds2760_read(dev, buf, off, count); } -static BIN_ATTR_RO(w1_slave, DS2760_DATA_SIZE); +static const BIN_ATTR_RO(w1_slave, DS2760_DATA_SIZE); -static struct bin_attribute *w1_ds2760_bin_attrs[] = { +static const struct bin_attribute *const w1_ds2760_bin_attrs[] = { &bin_attr_w1_slave, NULL, }; static const struct attribute_group w1_ds2760_group = { - .bin_attrs = w1_ds2760_bin_attrs, + .bin_attrs_new = w1_ds2760_bin_attrs, }; static const struct attribute_group *w1_ds2760_groups[] = { From patchwork Mon Dec 2 19:02:20 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: 846840 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 024901DE3D5; Mon, 2 Dec 2024 19:02:21 +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=1733166144; cv=none; b=TPt3ysl+ZjZOUsrlVM2QsOmDo3cAQwmlx6XcYXj3Lc4MeFMDgJ2pwtyT67ffBcj4HsDuaNwcUqG1vo+FUKhlfWF3L5SH+vWaUgLdm46HknFb2AK1AY7fJdTZn7AXGvZJ1bSvgeVqFgPXlkq+qZ8UyLwXdKuJEgZFJTz34qtDKwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733166144; c=relaxed/simple; bh=Z0h4ZU5IdA8MLG7R/DevJ7HuP4dynhwfphEzIsEpgUE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UMrGfFNdtAGxS7b/u/qf3derzZcLa4aPYwiN8ZlH9dKcj/wie5eFKCdjPiD9Iy6oc9MY1To6E418y1kmmHzGei6L9SAwa1sxKR2MSfXvRoECPEyhC7v4PMdRq/xqXh4c7JnYSWoQfpT0JPrrkdPf2CNCjL0BiEtBLdK9UJdyCrU= 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=DnWALlZl; 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="DnWALlZl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733166139; bh=Z0h4ZU5IdA8MLG7R/DevJ7HuP4dynhwfphEzIsEpgUE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=DnWALlZlflbrMuJygvQRNC1ziGST2Zo9fMRojnXzCabB+tglAvqABG9/EDZmfVVza Zta2HnH6SEywXShidZGOLnwgnPUvnymJmRrpc6JQt3sCemLxH8gnE1Z4jQhCxJuidk q++R7xR5dJoH9MY0Hut0IhpwmhmsZ4Y+R/k6WScs= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 02 Dec 2024 20:02:20 +0100 Subject: [PATCH 2/4] power: supply: ds2780: constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241202-sysfs-const-bin_attr-psy-v1-2-f846430b8b66@weissschuh.net> References: <20241202-sysfs-const-bin_attr-psy-v1-0-f846430b8b66@weissschuh.net> In-Reply-To: <20241202-sysfs-const-bin_attr-psy-v1-0-f846430b8b66@weissschuh.net> To: Sebastian Reichel Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas?= =?utf-8?q?_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733166139; l=3753; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=Z0h4ZU5IdA8MLG7R/DevJ7HuP4dynhwfphEzIsEpgUE=; b=IlF5wI4owF498zfnb+j16PVNeEG8Qvr5mIy1b4ojXCInXQQhBXtRNMlKDuilGbPZpv583U5yr 9cItBx43RJxAaWXkbTNMjeavqGXcmEbdcXUL42dB7KsZeXap1q7pbNG 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/power/supply/ds2780_battery.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/power/supply/ds2780_battery.c b/drivers/power/supply/ds2780_battery.c index 1e7f297f6cb181e6ab7dc8e47b638aa43db8db97..dd9ac7a3296716d8ab72db56c1d9c0e439c3b2a9 100644 --- a/drivers/power/supply/ds2780_battery.c +++ b/drivers/power/supply/ds2780_battery.c @@ -621,7 +621,7 @@ static ssize_t ds2780_set_pio_pin(struct device *dev, static ssize_t ds2780_read_param_eeprom_bin(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct device *dev = kobj_to_dev(kobj); @@ -634,7 +634,7 @@ static ssize_t ds2780_read_param_eeprom_bin(struct file *filp, static ssize_t ds2780_write_param_eeprom_bin(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct device *dev = kobj_to_dev(kobj); @@ -654,19 +654,19 @@ static ssize_t ds2780_write_param_eeprom_bin(struct file *filp, return count; } -static struct bin_attribute ds2780_param_eeprom_bin_attr = { +static const struct bin_attribute ds2780_param_eeprom_bin_attr = { .attr = { .name = "param_eeprom", .mode = S_IRUGO | S_IWUSR, }, .size = DS2780_PARAM_EEPROM_SIZE, - .read = ds2780_read_param_eeprom_bin, - .write = ds2780_write_param_eeprom_bin, + .read_new = ds2780_read_param_eeprom_bin, + .write_new = ds2780_write_param_eeprom_bin, }; static ssize_t ds2780_read_user_eeprom_bin(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct device *dev = kobj_to_dev(kobj); @@ -679,7 +679,7 @@ static ssize_t ds2780_read_user_eeprom_bin(struct file *filp, static ssize_t ds2780_write_user_eeprom_bin(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct device *dev = kobj_to_dev(kobj); @@ -699,14 +699,14 @@ static ssize_t ds2780_write_user_eeprom_bin(struct file *filp, return count; } -static struct bin_attribute ds2780_user_eeprom_bin_attr = { +static const struct bin_attribute ds2780_user_eeprom_bin_attr = { .attr = { .name = "user_eeprom", .mode = S_IRUGO | S_IWUSR, }, .size = DS2780_USER_EEPROM_SIZE, - .read = ds2780_read_user_eeprom_bin, - .write = ds2780_write_user_eeprom_bin, + .read_new = ds2780_read_user_eeprom_bin, + .write_new = ds2780_write_user_eeprom_bin, }; static DEVICE_ATTR(pmod_enabled, S_IRUGO | S_IWUSR, ds2780_get_pmod_enabled, @@ -726,7 +726,7 @@ static struct attribute *ds2780_sysfs_attrs[] = { NULL }; -static struct bin_attribute *ds2780_sysfs_bin_attrs[] = { +static const struct bin_attribute *const ds2780_sysfs_bin_attrs[] = { &ds2780_param_eeprom_bin_attr, &ds2780_user_eeprom_bin_attr, NULL @@ -734,7 +734,7 @@ static struct bin_attribute *ds2780_sysfs_bin_attrs[] = { static const struct attribute_group ds2780_sysfs_group = { .attrs = ds2780_sysfs_attrs, - .bin_attrs = ds2780_sysfs_bin_attrs, + .bin_attrs_new = ds2780_sysfs_bin_attrs, }; static const struct attribute_group *ds2780_sysfs_groups[] = { From patchwork Mon Dec 2 19:02:22 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: 846842 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 082681DE3D6; Mon, 2 Dec 2024 19:02:21 +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=1733166142; cv=none; b=oWkGknCaLR+rxaI7bQfI7OYpO7Gmxop8HvCzIfVUvQr6BD+UwlVwHVE6kN0RVL7nOXrNZsfU7BjumGLitCmv2YnXyvvVh5scs6A8gfoU9WiSf9A4XMIijdEh9WECcAc1yQGe83Yj0f6q4QglB2DFeLXjUaTXCAEvDpwUsfcpGVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733166142; c=relaxed/simple; bh=A/SStIoFKy8kbXNZOyVWGy/f5MASnx/GCLKsixaNTdk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MU69b38tNgFE22p7XRZ6x86IqEwhjAW2QXiAwkOGHDLqWRvmlQKaEK9bTFkIDboAdMoqmdNpo/ZQelXugwR3HRY5jINzwLn09ruJ/mqWTfCLFvgCh8UV+RW5DeDLOxHiCv972lBEA2iQ/tC750Jauq7UZma5uYczgSJMEnhyK/Y= 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=WWDfbsFE; 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="WWDfbsFE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733166139; bh=A/SStIoFKy8kbXNZOyVWGy/f5MASnx/GCLKsixaNTdk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=WWDfbsFECbI5pH2MbvT8xeRBe7ZXOgSN9Q+EMIv464oqwsMZLyZ3JAXHyq2qlbIj1 sG2RBqiaow0zHSGHvEIuKWr5b7gKmEvcj1CqHQtyGpcQXaQM02i3b7AWY+RItOIDhm z8MSZDTIU/QK2wun8gQfSjzsi7a5f4iKzXU6mZIw= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 02 Dec 2024 20:02:22 +0100 Subject: [PATCH 4/4] power: supply: olpc_battery: constify 'struct bin_attribute' Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241202-sysfs-const-bin_attr-psy-v1-4-f846430b8b66@weissschuh.net> References: <20241202-sysfs-const-bin_attr-psy-v1-0-f846430b8b66@weissschuh.net> In-Reply-To: <20241202-sysfs-const-bin_attr-psy-v1-0-f846430b8b66@weissschuh.net> To: Sebastian Reichel Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas?= =?utf-8?q?_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733166139; l=2026; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=A/SStIoFKy8kbXNZOyVWGy/f5MASnx/GCLKsixaNTdk=; b=FxrGRdi3lo6HqtQ+teIFEkVolU18SzAS9SKr08rAliQyG1mmV84tBdGLhCdtxwdOknZ3hu0BU /jd8ttqcCmFBxOg+V7nHbNOv/vgA45DPv/YUSJ/BxSVw3TTf+6Gg3ir 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/power/supply/olpc_battery.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/power/supply/olpc_battery.c b/drivers/power/supply/olpc_battery.c index 9f60094a5599edd995588b2a7c3d753aaf8dd6ec..849f63e89ba09047bba30813723512780b9cdeb0 100644 --- a/drivers/power/supply/olpc_battery.c +++ b/drivers/power/supply/olpc_battery.c @@ -527,7 +527,7 @@ static enum power_supply_property olpc_xo15_bat_props[] = { #define EEPROM_SIZE (EEPROM_END - EEPROM_START) static ssize_t olpc_bat_eeprom_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, loff_t off, size_t count) + const struct bin_attribute *attr, char *buf, loff_t off, size_t count) { uint8_t ec_byte; int ret; @@ -547,13 +547,13 @@ static ssize_t olpc_bat_eeprom_read(struct file *filp, struct kobject *kobj, return count; } -static struct bin_attribute olpc_bat_eeprom = { +static const struct bin_attribute olpc_bat_eeprom = { .attr = { .name = "eeprom", .mode = S_IRUGO, }, .size = EEPROM_SIZE, - .read = olpc_bat_eeprom_read, + .read_new = olpc_bat_eeprom_read, }; /* Allow userspace to see the specific error value pulled from the EC */ @@ -584,15 +584,14 @@ static struct attribute *olpc_bat_sysfs_attrs[] = { NULL }; -static struct bin_attribute *olpc_bat_sysfs_bin_attrs[] = { +static const struct bin_attribute *const olpc_bat_sysfs_bin_attrs[] = { &olpc_bat_eeprom, NULL }; static const struct attribute_group olpc_bat_sysfs_group = { .attrs = olpc_bat_sysfs_attrs, - .bin_attrs = olpc_bat_sysfs_bin_attrs, - + .bin_attrs_new = olpc_bat_sysfs_bin_attrs, }; static const struct attribute_group *olpc_bat_sysfs_groups[] = {