Skip to contentSkip to conversation

block: constify some structures of partitions/core.c

PATCH Applied Thomas Weißschuh 2 participants 6 messages May 30, 2023 Block layer

lore
Share & tools
lore
#0 lore raw

v3 cover block: constify some structures of partitions/core.c

A few structures containing function pointers that could and should be const are not. Change that.

---
Changes in v3:
- Rebase on for-6.5/block
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Use correct syntax for const array of function pointers.
Reported by LKP bot.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Thomas Weißschuh (4):
block: constify partition prober array
block: constify struct part_type part_type
block: constify struct part_attr_group
block: constify the whole_disk device_attribute

 block/partitions/core.c | 8 ++++----
 include/linux/blkdev.h  | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

---
base-commit: 403b6fb8dac1e9407c04652cedd92285c5ae9aa5
change-id: 20230419-const-partition-a06b9f76b2f3

Best regards,

Signature · 1 line
Thomas Weißschuh <[email protected]>
#1 lore raw

PATCH v3 1/4 block: constify partition prober array

The array is never modified so it can be const.

---
 block/partitions/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/partitions/core.c +1 -1
index 49e0496ff23c..650603dbe557 100644
@@ -12,7 +12,7 @@
 #include <linux/raid/detect.h>
 #include "check.h"
 
-static int (*check_part[])(struct parsed_partitions *) = {
+static int (*const check_part[])(struct parsed_partitions *) = {
 	/*
 	 * Probe partition formats with tables at disk address 0
 	 * that also have an ADFS boot block at 0xdc0.
Signature · 1 line
2.40.1
#2 lore raw

PATCH v3 2/4 block: constify struct part_type part_type

In reply to Thomas Weißschuh

The struct is never modified so it can be const.

---
 block/partitions/core.c | 2 +-
 include/linux/blkdev.h  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
block/partitions/core.c +1 -1
index 650603dbe557..2bc21063edef 100644
@@ -256,7 +256,7 @@ static int part_uevent(const struct device *dev, struct kobj_uevent_env *env)
 	return 0;
 }
 
-struct device_type part_type = {
+const struct device_type part_type = {
 	.name		= "partition",
 	.groups		= part_attr_groups,
 	.release	= part_release,
include/linux/blkdev.h +1 -1
index b2ac587e3402..d89c2da14698 100644
@@ -41,7 +41,7 @@ struct blk_stat_callback;
 struct blk_crypto_profile;
 
 extern const struct device_type disk_type;
-extern struct device_type part_type;
+extern const struct device_type part_type;
 extern struct class block_class;
 
 /*
Signature · 1 line
2.40.1
#3 lore raw

PATCH v3 3/4 block: constify struct part_attr_group

In reply to Thomas Weißschuh

The struct is never modified so it can be const.

---
 block/partitions/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/partitions/core.c +1 -1
index 2bc21063edef..d5f5633bf725 100644
@@ -228,7 +228,7 @@ static struct attribute *part_attrs[] = {
 	NULL
 };
 
-static struct attribute_group part_attr_group = {
+static const struct attribute_group part_attr_group = {
 	.attrs = part_attrs,
 };
 
Signature · 1 line
2.40.1
#4 lore raw

PATCH v3 4/4 block: constify the whole_disk device_attribute

In reply to Thomas Weißschuh

The struct is never modified so it can be const.

---
 block/partitions/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/partitions/core.c +1 -1
index d5f5633bf725..82d26427deae 100644
@@ -288,7 +288,7 @@ static ssize_t whole_disk_show(struct device *dev,
 {
 	return 0;
 }
-static DEVICE_ATTR(whole_disk, 0444, whole_disk_show, NULL);
+static const DEVICE_ATTR(whole_disk, 0444, whole_disk_show, NULL);
 
 /*
  * Must be called either with open_mutex held, before a disk can be opened or
Signature · 1 line
2.40.1
maintainer Applied
#5 lore raw
In reply to Thomas Weißschuh
Quoted 4 lines · Thomas Weißschuh

A few structures containing function pointers that could and should be const are not. Change that.

Applied, thanks!

[1/4] block: constify partition prober array

      commit: 539050f92ea7666bca17c2c380d8071d2f93dcde
[2/4] block: constify struct part_type part_type
      commit: cdb37f73cf05631c4f7401f2cd99878733c0c3d9
[3/4] block: constify struct part_attr_group
      commit: 0bd478005cfc7f50ccb769744d952e9687ee75b4
[4/4] block: constify the whole_disk device_attribute
      commit: a378f6a40fac4a2f1812adea7017613d2bd5dab6

Best regards,

Signature · 1 line
Jens Axboe