* [PATCH] accel/habanalabs: constify 'struct bin_attribute'
@ 2024-12-16 12:25 Thomas Weißschuh
2024-12-16 12:28 ` Jani Nikula
0 siblings, 1 reply; 2+ messages in thread
From: Thomas Weißschuh @ 2024-12-16 12:25 UTC (permalink / raw)
To: Ofir Bitton, Oded Gabbay; +Cc: dri-devel, linux-kernel, Thomas Weißschuh
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 <linux@weissschuh.net>
---
drivers/accel/habanalabs/common/sysfs.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/accel/habanalabs/common/sysfs.c b/drivers/accel/habanalabs/common/sysfs.c
index e9f8ccc0bbf9d4dabec1b51072d07170c51ffc9e..9d58efa2ff380c8773bd79bea613dc79a5a98020 100644
--- a/drivers/accel/habanalabs/common/sysfs.c
+++ b/drivers/accel/habanalabs/common/sysfs.c
@@ -368,7 +368,7 @@ static ssize_t max_power_store(struct device *dev,
}
static ssize_t eeprom_read_handler(struct file *filp, struct kobject *kobj,
- struct bin_attribute *attr, char *buf, loff_t offset,
+ const struct bin_attribute *attr, char *buf, loff_t offset,
size_t max_size)
{
struct device *dev = kobj_to_dev(kobj);
@@ -443,10 +443,10 @@ static DEVICE_ATTR_RO(security_enabled);
static DEVICE_ATTR_RO(module_id);
static DEVICE_ATTR_RO(parent_device);
-static struct bin_attribute bin_attr_eeprom = {
+static const struct bin_attribute bin_attr_eeprom = {
.attr = {.name = "eeprom", .mode = (0444)},
.size = PAGE_SIZE,
- .read = eeprom_read_handler
+ .read_new = eeprom_read_handler
};
static struct attribute *hl_dev_attrs[] = {
@@ -472,14 +472,14 @@ static struct attribute *hl_dev_attrs[] = {
NULL,
};
-static struct bin_attribute *hl_dev_bin_attrs[] = {
+static const struct bin_attribute *const hl_dev_bin_attrs[] = {
&bin_attr_eeprom,
NULL
};
static struct attribute_group hl_dev_attr_group = {
.attrs = hl_dev_attrs,
- .bin_attrs = hl_dev_bin_attrs,
+ .bin_attrs_new = hl_dev_bin_attrs,
};
static struct attribute_group hl_dev_clks_attr_group;
---
base-commit: 78d4f34e2115b517bcbfe7ec0d018bbbb6f9b0b8
change-id: 20241216-sysfs-const-bin_attr-habanalabs-8c95e852dd8a
Best regards,
--
Thomas Weißschuh <linux@weissschuh.net>
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] accel/habanalabs: constify 'struct bin_attribute'
2024-12-16 12:25 [PATCH] accel/habanalabs: constify 'struct bin_attribute' Thomas Weißschuh
@ 2024-12-16 12:28 ` Jani Nikula
0 siblings, 0 replies; 2+ messages in thread
From: Jani Nikula @ 2024-12-16 12:28 UTC (permalink / raw)
To: Thomas Weißschuh, Ofir Bitton, Oded Gabbay
Cc: dri-devel, linux-kernel, Thomas Weißschuh
On Mon, 16 Dec 2024, Thomas Weißschuh <linux@weissschuh.net> wrote:
> 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 <linux@weissschuh.net>
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
> ---
> drivers/accel/habanalabs/common/sysfs.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/accel/habanalabs/common/sysfs.c b/drivers/accel/habanalabs/common/sysfs.c
> index e9f8ccc0bbf9d4dabec1b51072d07170c51ffc9e..9d58efa2ff380c8773bd79bea613dc79a5a98020 100644
> --- a/drivers/accel/habanalabs/common/sysfs.c
> +++ b/drivers/accel/habanalabs/common/sysfs.c
> @@ -368,7 +368,7 @@ static ssize_t max_power_store(struct device *dev,
> }
>
> static ssize_t eeprom_read_handler(struct file *filp, struct kobject *kobj,
> - struct bin_attribute *attr, char *buf, loff_t offset,
> + const struct bin_attribute *attr, char *buf, loff_t offset,
> size_t max_size)
> {
> struct device *dev = kobj_to_dev(kobj);
> @@ -443,10 +443,10 @@ static DEVICE_ATTR_RO(security_enabled);
> static DEVICE_ATTR_RO(module_id);
> static DEVICE_ATTR_RO(parent_device);
>
> -static struct bin_attribute bin_attr_eeprom = {
> +static const struct bin_attribute bin_attr_eeprom = {
> .attr = {.name = "eeprom", .mode = (0444)},
> .size = PAGE_SIZE,
> - .read = eeprom_read_handler
> + .read_new = eeprom_read_handler
> };
>
> static struct attribute *hl_dev_attrs[] = {
> @@ -472,14 +472,14 @@ static struct attribute *hl_dev_attrs[] = {
> NULL,
> };
>
> -static struct bin_attribute *hl_dev_bin_attrs[] = {
> +static const struct bin_attribute *const hl_dev_bin_attrs[] = {
> &bin_attr_eeprom,
> NULL
> };
>
> static struct attribute_group hl_dev_attr_group = {
> .attrs = hl_dev_attrs,
> - .bin_attrs = hl_dev_bin_attrs,
> + .bin_attrs_new = hl_dev_bin_attrs,
> };
>
> static struct attribute_group hl_dev_clks_attr_group;
>
> ---
> base-commit: 78d4f34e2115b517bcbfe7ec0d018bbbb6f9b0b8
> change-id: 20241216-sysfs-const-bin_attr-habanalabs-8c95e852dd8a
>
> Best regards,
--
Jani Nikula, Intel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-12-16 12:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-16 12:25 [PATCH] accel/habanalabs: constify 'struct bin_attribute' Thomas Weißschuh
2024-12-16 12:28 ` Jani Nikula
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.