2023-04-19 13:25:56

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH v2 0/4] block: constify some structures of partitions/core.c

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

Signed-off-by: Thomas Weißschuh <[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: af67688dca57999fd848f051eeea1d375ba546b2
change-id: 20230419-const-partition-a06b9f76b2f3

Best regards,
--
Thomas Weißschuh <[email protected]>


2023-04-19 13:25:57

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH v2 1/4] block: constify partition prober array

The array is never modified so it can be const.

Reported-by: kernel test robot <[email protected]>
Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Signed-off-by: Thomas Weißschuh <[email protected]>
---
block/partitions/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/partitions/core.c b/block/partitions/core.c
index 7b8ef6296abd..890072ae5c7c 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -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.

--
2.40.0

2023-04-19 13:26:07

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH v2 3/4] block: constify struct part_attr_group

The struct is never modified so it can be const.

Signed-off-by: Thomas Weißschuh <[email protected]>
---
block/partitions/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/partitions/core.c b/block/partitions/core.c
index 43bde8118a78..cb37ac71868e 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -236,7 +236,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,
};


--
2.40.0

2023-04-19 13:26:20

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH v2 4/4] block: constify the whole_disk device_attribute

The struct is never modified so it can be const.

Signed-off-by: Thomas Weißschuh <[email protected]>
---
block/partitions/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/partitions/core.c b/block/partitions/core.c
index cb37ac71868e..302ac06708e6 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -296,7 +296,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

--
2.40.0

2023-05-30 16:59:20

by Thomas Weißschuh

[permalink] [raw]
Subject: Re: [PATCH v2 0/4] block: constify some structures of partitions/core.c

Hi Jens,

could you take a look at this?

Thanks,
Thomas

On 2023-04-19 15:22:52+0200, Thomas Weißschuh wrote:
> A few structures containing function pointers that could and should be
> const are not. Change that.
>
> Signed-off-by: Thomas Weißschuh <[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: af67688dca57999fd848f051eeea1d375ba546b2
> change-id: 20230419-const-partition-a06b9f76b2f3
>
> Best regards,
> --
> Thomas Weißschuh <[email protected]>
>

2023-05-30 17:12:52

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH v2 0/4] block: constify some structures of partitions/core.c

On 5/30/23 10:52 AM, Thomas Weißschuh wrote:
> Hi Jens,
>
> could you take a look at this?

Looks fine to me, more const always a good thing. Can you respin
it against for-6.5/block?

--
Jens Axboe