Skip to contentSkip to conversation

HID: make hid_bus_type const

PATCH Applied Greg Kroah-Hartman 3 participants 6 messages Dec 20, 2023 – Jan 4, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 HID: make hid_bus_type const

Now that the driver core can properly handle constant struct bus_type, move the hid_bus_type variable to be a constant structure as well, placing it into read-only memory which can not be modified at runtime.

---
 drivers/hid/hid-core.c | 2 +-
 include/linux/hid.h    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/hid/hid-core.c +1 -1
index e0181218ad85..de7a477d6665 100644
@@ -2749,7 +2749,7 @@ static int hid_uevent(const struct device *dev, struct kobj_uevent_env *env)
 	return 0;
 }
 
-struct bus_type hid_bus_type = {
+const struct bus_type hid_bus_type = {
 	.name		= "hid",
 	.dev_groups	= hid_dev_groups,
 	.drv_groups	= hid_drv_groups,
include/linux/hid.h +1 -1
index bf43f3ff6664..7c26db874ff0 100644
@@ -912,7 +912,7 @@ extern bool hid_ignore(struct hid_device *);
 extern int hid_add_device(struct hid_device *);
 extern void hid_destroy_device(struct hid_device *);
 
-extern struct bus_type hid_bus_type;
+extern const struct bus_type hid_bus_type;
 
 extern int __must_check __hid_register_driver(struct hid_driver *,
 		struct module *, const char *mod_name);
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/3 HID: make ishtp_cl_bus_type const

Now that the driver core can properly handle constant struct bus_type, move the ishtp_cl_bus_type variable to be a constant structure as well, placing it into read-only memory which can not be modified at runtime.

Cc Srinivas Pandruvada <[email protected]>
Cc Jiri Kosina <[email protected]>
Cc Benjamin Tissoires <[email protected]>
---
 drivers/hid/intel-ish-hid/ishtp/bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/intel-ish-hid/ishtp/bus.c +1 -1
index 7fc738a22375..aa6cb033bb06 100644
@@ -378,7 +378,7 @@ static const struct dev_pm_ops ishtp_cl_bus_dev_pm_ops = {
 	.restore = ishtp_cl_device_resume,
 };
 
-static struct bus_type ishtp_cl_bus_type = {
+static const struct bus_type ishtp_cl_bus_type = {
 	.name		= "ishtp",
 	.dev_groups	= ishtp_cl_dev_groups,
 	.probe		= ishtp_cl_device_probe,
Signature · 1 line
2.43.0
maintainer Acked-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] HID: make ishtp_cl_bus_type const

Quoted 7 lines · Greg Kroah-Hartman

Now that the driver core can properly handle constant struct bus_type,
move the ishtp_cl_bus_type variable to be a constant structure as well,
placing it into read-only memory which can not be modified at runtime.

Quoted 5 lines
Cc Srinivas Pandruvada <[email protected]>
Cc Jiri Kosina <[email protected]>
Cc Benjamin Tissoires <[email protected]>
Quoted 19 lines

---
 drivers/hid/intel-ish-hid/ishtp/bus.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/intel-ish-hid/ishtp/bus.c +0 -0
index 7fc738a22375..aa6cb033bb06 100644
@@ -378,7 +378,7 @@ static const struct dev_pm_ops
 ishtp_cl_bus_dev_pm_ops = {
         .restore = ishtp_cl_device_resume,
  };

drivers/hid/intel-ish-hid/ishtp/bus.c +1 -1
-static struct bus_type ishtp_cl_bus_type = {
+static const struct bus_type ishtp_cl_bus_type = {

        .name           = "ishtp",
        .dev_groups     = ishtp_cl_dev_groups,
        .probe          = ishtp_cl_device_probe,

#3 lore raw

PATCH 3/3 HID: bpf: make bus_type const in struct hid_bpf_ops

In reply to Greg Kroah-Hartman

The struct bus_type pointer in hid_bpf_ops just passes the pointer to the driver core, and the driver core can handle, and expects, a constant pointer, so also make the pointer constant in hid_bpf_ops.

Part of the process of moving all usages of struct bus_type to be constant to move them all to read-only memory.

---
 include/linux/hid_bpf.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/hid_bpf.h +1 -1
index e9afb61e6ee0..840cd254172d 100644
@@ -115,7 +115,7 @@ struct hid_bpf_ops {
 				  size_t len, enum hid_report_type rtype,
 				  enum hid_class_request reqtype);
 	struct module *owner;
-	struct bus_type *bus_type;
+	const struct bus_type *bus_type;
 };
 
 extern struct hid_bpf_ops *hid_bpf_ops;
Signature · 1 line
2.43.0
Applied
#4 lore raw
In reply to Greg Kroah-Hartman
Quoted 3 lines · Greg Kroah-Hartman

Now that the driver core can properly handle constant struct bus_type, move the hid_bus_type variable to be a constant structure as well, placing it into read-only memory which can not be modified at runtime.

I have applied all three patches to hid.git now. Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#5 lore raw
Quoted 7 lines · Jiri Kosina
Quoted 3 lines · Greg Kroah-Hartman

Now that the driver core can properly handle constant struct bus_type, move the hid_bus_type variable to be a constant structure as well, placing it into read-only memory which can not be modified at runtime.

I have applied all three patches to hid.git now. Thanks,

Thanks!