From nobody Tue Feb 10 11:14:38 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D40771DE8AD; Mon, 2 Dec 2024 19:01:42 +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=1733166104; cv=none; b=PMQRv6Hf839lbSpFihZmPauDel3jhYzWAdSsXtHSHt1NEH9xbIIn+ij7QPhQahOELQ1XIOHcV1KWqsPOcOP04rlLFnBI7UQg2W/qsUQYFYYTBjnZ1LetqXalxhniZqT5f5VpF36Yd3fz47jNwgX036/Hifu4ZINR1F8EtUnSJr8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733166104; c=relaxed/simple; bh=GrX8bTf9cJi04Oy6X8nbhkoX39lESfzTFSk3V/Mc9RM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SmWLrJReH5VzS9SW9kpEcP2TiqItUN5MaG7xrq+ZUxP3HbEmncmGuA4Qsgl94kN98V1n/AU/vs/JW1OVw9rUo4jmNEYzXlYcoq96ZtVcpDcn3/wMUpIOGci6GiyjHj3zPZojrwjF6vcpocau37CjNGLL2QoTV9t8QiSTqNnaKag= 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=NFfgHJrX; 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="NFfgHJrX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1733166098; bh=GrX8bTf9cJi04Oy6X8nbhkoX39lESfzTFSk3V/Mc9RM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NFfgHJrXrq4PKIYWGoyCf/HvmqVPVSxCrZSjBl3ziFOwqU8vHzoUpoh7QPRWUiD+S zn5ATxAMaCArER/zdzq47R1rEvY+E354ZSz5OxkcpkvsWsa147BURflZmIGclPIZiV Yi/8am2fIPSH/WqFTpLDeqlJ9fgTVghexHKd27Nk= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 02 Dec 2024 20:01:41 +0100 Subject: [PATCH 10/10] HID: roccat: pyro: constify 'struct bin_attribute' 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: <20241202-sysfs-const-bin_attr-hid-v1-10-16369423a48a@weissschuh.net> References: <20241202-sysfs-const-bin_attr-hid-v1-0-16369423a48a@weissschuh.net> In-Reply-To: <20241202-sysfs-const-bin_attr-hid-v1-0-16369423a48a@weissschuh.net> To: Jiri Kosina , Benjamin Tissoires , Stefan Achatz Cc: linux-input@vger.kernel.org, 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=1733166097; l=6442; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=GrX8bTf9cJi04Oy6X8nbhkoX39lESfzTFSk3V/Mc9RM=; b=k2BZMbPJN1o4kNzfgID5b+1W5//S6RZh0UBFaS6YvCL5pcXg4E1onTwgG6AWTBzNiAmpECi08 HjuQcd64FLND1/HM3I9EaBnYJCWDOvRyLua61Knn9t0DecND/OeBvI5 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=C3=9Fschuh --- drivers/hid/hid-roccat-pyra.c | 50 +++++++++++++++++++++------------------= ---- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c index eeb3d38cd80584bd716ad493cff2892a2d5af552..2b53fbfbb8979ad1d1994e462b6= 24b3f72480447 100644 --- a/drivers/hid/hid-roccat-pyra.c +++ b/drivers/hid/hid-roccat-pyra.c @@ -129,8 +129,8 @@ static ssize_t pyra_sysfs_write(struct file *fp, struct= kobject *kobj, =20 #define PYRA_SYSFS_W(thingy, THINGY) \ static ssize_t pyra_sysfs_write_ ## thingy(struct file *fp, \ - struct kobject *kobj, struct bin_attribute *attr, char *buf, \ - loff_t off, size_t count) \ + struct kobject *kobj, const struct bin_attribute *attr, \ + char *buf, loff_t off, size_t count) \ { \ return pyra_sysfs_write(fp, kobj, buf, off, count, \ PYRA_SIZE_ ## THINGY, PYRA_COMMAND_ ## THINGY); \ @@ -138,8 +138,8 @@ static ssize_t pyra_sysfs_write_ ## thingy(struct file = *fp, \ =20 #define PYRA_SYSFS_R(thingy, THINGY) \ static ssize_t pyra_sysfs_read_ ## thingy(struct file *fp, \ - struct kobject *kobj, struct bin_attribute *attr, char *buf, \ - loff_t off, size_t count) \ + struct kobject *kobj, const struct bin_attribute *attr, \ + char *buf, loff_t off, size_t count) \ { \ return pyra_sysfs_read(fp, kobj, buf, off, count, \ PYRA_SIZE_ ## THINGY, PYRA_COMMAND_ ## THINGY); \ @@ -151,27 +151,27 @@ PYRA_SYSFS_R(thingy, THINGY) =20 #define PYRA_BIN_ATTRIBUTE_RW(thingy, THINGY) \ PYRA_SYSFS_RW(thingy, THINGY); \ -static struct bin_attribute bin_attr_##thingy =3D { \ +static const struct bin_attribute bin_attr_##thingy =3D { \ .attr =3D { .name =3D #thingy, .mode =3D 0660 }, \ .size =3D PYRA_SIZE_ ## THINGY, \ - .read =3D pyra_sysfs_read_ ## thingy, \ - .write =3D pyra_sysfs_write_ ## thingy \ + .read_new =3D pyra_sysfs_read_ ## thingy, \ + .write_new =3D pyra_sysfs_write_ ## thingy \ } =20 #define PYRA_BIN_ATTRIBUTE_R(thingy, THINGY) \ PYRA_SYSFS_R(thingy, THINGY); \ -static struct bin_attribute bin_attr_##thingy =3D { \ +static const struct bin_attribute bin_attr_##thingy =3D { \ .attr =3D { .name =3D #thingy, .mode =3D 0440 }, \ - .size =3D PYRA_SIZE_ ## THINGY, \ - .read =3D pyra_sysfs_read_ ## thingy, \ + .size_new =3D PYRA_SIZE_ ## THINGY, \ + .read_new =3D pyra_sysfs_read_ ## thingy, \ } =20 #define PYRA_BIN_ATTRIBUTE_W(thingy, THINGY) \ PYRA_SYSFS_W(thingy, THINGY); \ -static struct bin_attribute bin_attr_##thingy =3D { \ +static const struct bin_attribute bin_attr_##thingy =3D { \ .attr =3D { .name =3D #thingy, .mode =3D 0220 }, \ .size =3D PYRA_SIZE_ ## THINGY, \ - .write =3D pyra_sysfs_write_ ## thingy \ + .write_new =3D pyra_sysfs_write_ ## thingy \ } =20 PYRA_BIN_ATTRIBUTE_W(control, CONTROL); @@ -180,8 +180,8 @@ PYRA_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTING= S); PYRA_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS); =20 static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp, - struct kobject *kobj, struct bin_attribute *attr, char *buf, - loff_t off, size_t count) + struct kobject *kobj, const struct bin_attribute *attr, + char *buf, loff_t off, size_t count) { struct device *dev =3D kobj_to_dev(kobj)->parent->parent; struct usb_device *usb_dev =3D interface_to_usbdev(to_usb_interface(dev)); @@ -198,8 +198,8 @@ static ssize_t pyra_sysfs_read_profilex_settings(struct= file *fp, } =20 static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp, - struct kobject *kobj, struct bin_attribute *attr, char *buf, - loff_t off, size_t count) + struct kobject *kobj, const struct bin_attribute *attr, + char *buf, loff_t off, size_t count) { struct device *dev =3D kobj_to_dev(kobj)->parent->parent; struct usb_device *usb_dev =3D interface_to_usbdev(to_usb_interface(dev)); @@ -216,16 +216,16 @@ static ssize_t pyra_sysfs_read_profilex_buttons(struc= t file *fp, } =20 #define PROFILE_ATTR(number) \ -static struct bin_attribute bin_attr_profile##number##_settings =3D { \ +static const struct bin_attribute bin_attr_profile##number##_settings =3D = { \ .attr =3D { .name =3D "profile" #number "_settings", .mode =3D 0440 }, \ .size =3D PYRA_SIZE_PROFILE_SETTINGS, \ - .read =3D pyra_sysfs_read_profilex_settings, \ + .read_new =3D pyra_sysfs_read_profilex_settings, \ .private =3D &profile_numbers[number-1], \ }; \ -static struct bin_attribute bin_attr_profile##number##_buttons =3D { \ +static const struct bin_attribute bin_attr_profile##number##_buttons =3D {= \ .attr =3D { .name =3D "profile" #number "_buttons", .mode =3D 0440 }, \ .size =3D PYRA_SIZE_PROFILE_BUTTONS, \ - .read =3D pyra_sysfs_read_profilex_buttons, \ + .read_new =3D pyra_sysfs_read_profilex_buttons, \ .private =3D &profile_numbers[number-1], \ }; PROFILE_ATTR(1); @@ -235,8 +235,8 @@ PROFILE_ATTR(4); PROFILE_ATTR(5); =20 static ssize_t pyra_sysfs_write_settings(struct file *fp, - struct kobject *kobj, struct bin_attribute *attr, char *buf, - loff_t off, size_t count) + struct kobject *kobj, const struct bin_attribute *attr, + char *buf, loff_t off, size_t count) { struct device *dev =3D kobj_to_dev(kobj)->parent->parent; struct pyra_device *pyra =3D hid_get_drvdata(dev_get_drvdata(dev)); @@ -273,7 +273,7 @@ static ssize_t pyra_sysfs_write_settings(struct file *f= p, } =20 PYRA_SYSFS_R(settings, SETTINGS); -static struct bin_attribute bin_attr_settings =3D +static const struct bin_attribute bin_attr_settings =3D __BIN_ATTR(settings, (S_IWUSR | S_IRUGO), pyra_sysfs_read_settings, pyra_sysfs_write_settings, PYRA_SIZE_SETTINGS); @@ -334,7 +334,7 @@ static struct attribute *pyra_attrs[] =3D { NULL, }; =20 -static struct bin_attribute *pyra_bin_attributes[] =3D { +static const struct bin_attribute *const pyra_bin_attributes[] =3D { &bin_attr_control, &bin_attr_info, &bin_attr_profile_settings, @@ -355,7 +355,7 @@ static struct bin_attribute *pyra_bin_attributes[] =3D { =20 static const struct attribute_group pyra_group =3D { .attrs =3D pyra_attrs, - .bin_attrs =3D pyra_bin_attributes, + .bin_attrs_new =3D pyra_bin_attributes, }; =20 static const struct attribute_group *pyra_groups[] =3D { --=20 2.47.1