]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
platform/x86/amd/hsmp: Constify 'struct bin_attribute'
authorThomas Weißschuh <linux@weissschuh.net>
Mon, 2 Dec 2024 19:38:36 +0000 (20:38 +0100)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tue, 17 Dec 2024 11:12:59 +0000 (13:12 +0200)
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>
Link: https://lore.kernel.org/r/20241202-sysfs-const-bin_attr-pdx86-v1-5-9ab204c2a814@weissschuh.net
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/amd/hsmp/acpi.c
drivers/platform/x86/amd/hsmp/plat.c

index e981d45e1c127973059e07203610bfdf3685c9f0..444b43be35a256f2f1b06c87b36747cc51faf4ea 100644 (file)
@@ -226,7 +226,7 @@ static int hsmp_parse_acpi_table(struct device *dev, u16 sock_ind)
 }
 
 static ssize_t hsmp_metric_tbl_acpi_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 = container_of(kobj, struct device, kobj);
@@ -285,19 +285,19 @@ static int init_acpi(struct device *dev)
        return ret;
 }
 
-static struct bin_attribute  hsmp_metric_tbl_attr = {
+static const struct bin_attribute  hsmp_metric_tbl_attr = {
        .attr = { .name = HSMP_METRICS_TABLE_NAME, .mode = 0444},
-       .read = hsmp_metric_tbl_acpi_read,
+       .read_new = hsmp_metric_tbl_acpi_read,
        .size = sizeof(struct hsmp_metric_table),
 };
 
-static struct bin_attribute *hsmp_attr_list[] = {
+static const struct bin_attribute *hsmp_attr_list[] = {
        &hsmp_metric_tbl_attr,
        NULL
 };
 
-static struct attribute_group hsmp_attr_grp = {
-       .bin_attrs = hsmp_attr_list,
+static const struct attribute_group hsmp_attr_grp = {
+       .bin_attrs_new = hsmp_attr_list,
        .is_bin_visible = hsmp_is_sock_attr_visible,
 };
 
index a61f815c9f8065385fa390cddaf4682035d74ce8..02ca85762b68660b36301f208c15d7609583d6b4 100644 (file)
@@ -59,7 +59,7 @@ static int amd_hsmp_pci_rdwr(struct hsmp_socket *sock, u32 offset,
 }
 
 static ssize_t hsmp_metric_tbl_plat_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 hsmp_socket *sock;
@@ -97,13 +97,13 @@ static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
  * is_bin_visible function is used to show / hide the necessary groups.
  */
 #define HSMP_BIN_ATTR(index, _list)                                    \
-static struct bin_attribute attr##index = {                            \
+static const struct bin_attribute attr##index = {                      \
        .attr = { .name = HSMP_METRICS_TABLE_NAME, .mode = 0444},       \
        .private = (void *)index,                                       \
-       .read = hsmp_metric_tbl_plat_read,                                      \
+       .read_new = hsmp_metric_tbl_plat_read,                          \
        .size = sizeof(struct hsmp_metric_table),                       \
 };                                                                     \
-static struct bin_attribute _list[] = {                                        \
+static const struct bin_attribute _list[] = {                          \
        &attr##index,                                                   \
        NULL                                                            \
 }
@@ -118,8 +118,8 @@ HSMP_BIN_ATTR(6, *sock6_attr_list);
 HSMP_BIN_ATTR(7, *sock7_attr_list);
 
 #define HSMP_BIN_ATTR_GRP(index, _list, _name)                 \
-static struct attribute_group sock##index##_attr_grp = {       \
-       .bin_attrs = _list,                                     \
+static const struct attribute_group sock##index##_attr_grp = { \
+       .bin_attrs_new = _list,                                 \
        .is_bin_visible = hsmp_is_sock_attr_visible,            \
        .name = #_name,                                         \
 }