* [PATCH 1/8] regulator: Use container_of_const() when all types are const
2025-11-26 16:58 [PATCH 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
@ 2025-11-26 16:58 ` Krzysztof Kozlowski
2025-11-26 17:33 ` Mark Brown
2025-11-26 16:58 ` [PATCH 2/8] regulator: bd71815: Constify pointers to 'regulator_desc' wrap struct Krzysztof Kozlowski
` (7 subsequent siblings)
8 siblings, 1 reply; 13+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 16:58 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Bartosz Golaszewski, Matthias Brugger,
AngeloGioacchino Del Regno, Samuel Kayode, Matti Vaittinen
Cc: linux-kernel, linux-arm-kernel, linux-mediatek, imx,
Krzysztof Kozlowski
Use container_of_const(), which is preferred over container_of(), when
the argument 'ptr' and returned pointer are already const, for better
code safety and readability.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
drivers/regulator/hi6421-regulator.c | 10 +++++-----
drivers/regulator/hi6421v530-regulator.c | 4 ++--
drivers/regulator/hi6421v600-regulator.c | 6 +++---
drivers/regulator/max77650-regulator.c | 6 +++---
drivers/regulator/mt6315-regulator.c | 6 +++---
drivers/regulator/pf1550-regulator.c | 24 ++++++++++++------------
6 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/drivers/regulator/hi6421-regulator.c b/drivers/regulator/hi6421-regulator.c
index 69d24728d6a4..cd06030c3587 100644
--- a/drivers/regulator/hi6421-regulator.c
+++ b/drivers/regulator/hi6421-regulator.c
@@ -387,7 +387,7 @@ static unsigned int hi6421_regulator_ldo_get_mode(struct regulator_dev *rdev)
const struct hi6421_regulator_info *info;
unsigned int reg_val;
- info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
+ info = container_of_const(rdev->desc, struct hi6421_regulator_info, desc);
regmap_read(rdev->regmap, rdev->desc->enable_reg, ®_val);
if (reg_val & info->mode_mask)
return REGULATOR_MODE_IDLE;
@@ -400,7 +400,7 @@ static unsigned int hi6421_regulator_buck_get_mode(struct regulator_dev *rdev)
const struct hi6421_regulator_info *info;
unsigned int reg_val;
- info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
+ info = container_of_const(rdev->desc, struct hi6421_regulator_info, desc);
regmap_read(rdev->regmap, rdev->desc->enable_reg, ®_val);
if (reg_val & info->mode_mask)
return REGULATOR_MODE_STANDBY;
@@ -414,7 +414,7 @@ static int hi6421_regulator_ldo_set_mode(struct regulator_dev *rdev,
const struct hi6421_regulator_info *info;
unsigned int new_mode;
- info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
+ info = container_of_const(rdev->desc, struct hi6421_regulator_info, desc);
switch (mode) {
case REGULATOR_MODE_NORMAL:
new_mode = 0;
@@ -439,7 +439,7 @@ static int hi6421_regulator_buck_set_mode(struct regulator_dev *rdev,
const struct hi6421_regulator_info *info;
unsigned int new_mode;
- info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
+ info = container_of_const(rdev->desc, struct hi6421_regulator_info, desc);
switch (mode) {
case REGULATOR_MODE_NORMAL:
new_mode = 0;
@@ -464,7 +464,7 @@ hi6421_regulator_ldo_get_optimum_mode(struct regulator_dev *rdev,
{
const struct hi6421_regulator_info *info;
- info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
+ info = container_of_const(rdev->desc, struct hi6421_regulator_info, desc);
if (load_uA > info->eco_microamp)
return REGULATOR_MODE_NORMAL;
diff --git a/drivers/regulator/hi6421v530-regulator.c b/drivers/regulator/hi6421v530-regulator.c
index b3ebd1624814..1822f5daf6ce 100644
--- a/drivers/regulator/hi6421v530-regulator.c
+++ b/drivers/regulator/hi6421v530-regulator.c
@@ -110,7 +110,7 @@ static unsigned int hi6421v530_regulator_ldo_get_mode(
const struct hi6421v530_regulator_info *info;
unsigned int reg_val;
- info = container_of(rdev->desc, struct hi6421v530_regulator_info, rdesc);
+ info = container_of_const(rdev->desc, struct hi6421v530_regulator_info, rdesc);
regmap_read(rdev->regmap, rdev->desc->enable_reg, ®_val);
if (reg_val & (info->mode_mask))
@@ -125,7 +125,7 @@ static int hi6421v530_regulator_ldo_set_mode(struct regulator_dev *rdev,
const struct hi6421v530_regulator_info *info;
unsigned int new_mode;
- info = container_of(rdev->desc, struct hi6421v530_regulator_info, rdesc);
+ info = container_of_const(rdev->desc, struct hi6421v530_regulator_info, rdesc);
switch (mode) {
case REGULATOR_MODE_NORMAL:
new_mode = 0;
diff --git a/drivers/regulator/hi6421v600-regulator.c b/drivers/regulator/hi6421v600-regulator.c
index e5f6fbfc9016..e7c8bc10cf24 100644
--- a/drivers/regulator/hi6421v600-regulator.c
+++ b/drivers/regulator/hi6421v600-regulator.c
@@ -121,7 +121,7 @@ static unsigned int hi6421_spmi_regulator_get_mode(struct regulator_dev *rdev)
const struct hi6421_spmi_reg_info *sreg;
unsigned int reg_val;
- sreg = container_of(rdev->desc, struct hi6421_spmi_reg_info, desc);
+ sreg = container_of_const(rdev->desc, struct hi6421_spmi_reg_info, desc);
regmap_read(rdev->regmap, rdev->desc->enable_reg, ®_val);
if (reg_val & sreg->eco_mode_mask)
@@ -136,7 +136,7 @@ static int hi6421_spmi_regulator_set_mode(struct regulator_dev *rdev,
const struct hi6421_spmi_reg_info *sreg;
unsigned int val;
- sreg = container_of(rdev->desc, struct hi6421_spmi_reg_info, desc);
+ sreg = container_of_const(rdev->desc, struct hi6421_spmi_reg_info, desc);
switch (mode) {
case REGULATOR_MODE_NORMAL:
val = 0;
@@ -162,7 +162,7 @@ hi6421_spmi_regulator_get_optimum_mode(struct regulator_dev *rdev,
{
const struct hi6421_spmi_reg_info *sreg;
- sreg = container_of(rdev->desc, struct hi6421_spmi_reg_info, desc);
+ sreg = container_of_const(rdev->desc, struct hi6421_spmi_reg_info, desc);
if (!sreg->eco_uA || ((unsigned int)load_uA > sreg->eco_uA))
return REGULATOR_MODE_NORMAL;
diff --git a/drivers/regulator/max77650-regulator.c b/drivers/regulator/max77650-regulator.c
index 7368f54f046d..a809264c77fc 100644
--- a/drivers/regulator/max77650-regulator.c
+++ b/drivers/regulator/max77650-regulator.c
@@ -68,7 +68,7 @@ static int max77650_regulator_is_enabled(struct regulator_dev *rdev)
struct regmap *map;
int val, rv, en;
- rdesc = container_of(rdev->desc, struct max77650_regulator_desc, desc);
+ rdesc = container_of_const(rdev->desc, struct max77650_regulator_desc, desc);
map = rdev_get_regmap(rdev);
rv = regmap_read(map, rdesc->regB, &val);
@@ -85,7 +85,7 @@ static int max77650_regulator_enable(struct regulator_dev *rdev)
const struct max77650_regulator_desc *rdesc;
struct regmap *map;
- rdesc = container_of(rdev->desc, struct max77650_regulator_desc, desc);
+ rdesc = container_of_const(rdev->desc, struct max77650_regulator_desc, desc);
map = rdev_get_regmap(rdev);
return regmap_update_bits(map, rdesc->regB,
@@ -98,7 +98,7 @@ static int max77650_regulator_disable(struct regulator_dev *rdev)
const struct max77650_regulator_desc *rdesc;
struct regmap *map;
- rdesc = container_of(rdev->desc, struct max77650_regulator_desc, desc);
+ rdesc = container_of_const(rdev->desc, struct max77650_regulator_desc, desc);
map = rdev_get_regmap(rdev);
return regmap_update_bits(map, rdesc->regB,
diff --git a/drivers/regulator/mt6315-regulator.c b/drivers/regulator/mt6315-regulator.c
index 2608a6652d77..d3f93aae0fc5 100644
--- a/drivers/regulator/mt6315-regulator.c
+++ b/drivers/regulator/mt6315-regulator.c
@@ -80,7 +80,7 @@ static unsigned int mt6315_regulator_get_mode(struct regulator_dev *rdev)
int ret, regval;
u32 modeset_mask;
- info = container_of(rdev->desc, struct mt6315_regulator_info, desc);
+ info = container_of_const(rdev->desc, struct mt6315_regulator_info, desc);
modeset_mask = init->modeset_mask[rdev_get_id(rdev)];
ret = regmap_read(rdev->regmap, MT6315_BUCK_TOP_4PHASE_ANA_CON42, ®val);
if (ret != 0) {
@@ -111,7 +111,7 @@ static int mt6315_regulator_set_mode(struct regulator_dev *rdev,
int ret, val, curr_mode;
u32 modeset_mask;
- info = container_of(rdev->desc, struct mt6315_regulator_info, desc);
+ info = container_of_const(rdev->desc, struct mt6315_regulator_info, desc);
modeset_mask = init->modeset_mask[rdev_get_id(rdev)];
curr_mode = mt6315_regulator_get_mode(rdev);
switch (mode) {
@@ -165,7 +165,7 @@ static int mt6315_get_status(struct regulator_dev *rdev)
int ret;
u32 regval;
- info = container_of(rdev->desc, struct mt6315_regulator_info, desc);
+ info = container_of_const(rdev->desc, struct mt6315_regulator_info, desc);
ret = regmap_read(rdev->regmap, info->status_reg, ®val);
if (ret < 0) {
dev_err(&rdev->dev, "Failed to get enable reg: %d\n", ret);
diff --git a/drivers/regulator/pf1550-regulator.c b/drivers/regulator/pf1550-regulator.c
index 904926097738..037b8ec94066 100644
--- a/drivers/regulator/pf1550-regulator.c
+++ b/drivers/regulator/pf1550-regulator.c
@@ -71,9 +71,9 @@ static int pf1550_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
static int pf1550_set_suspend_enable(struct regulator_dev *rdev)
{
- const struct pf1550_desc *desc = container_of(rdev->desc,
- struct pf1550_desc,
- desc);
+ const struct pf1550_desc *desc = container_of_const(rdev->desc,
+ struct pf1550_desc,
+ desc);
unsigned int val = desc->stby_enable_mask;
return regmap_update_bits(rdev->regmap, desc->stby_enable_reg,
@@ -82,9 +82,9 @@ static int pf1550_set_suspend_enable(struct regulator_dev *rdev)
static int pf1550_set_suspend_disable(struct regulator_dev *rdev)
{
- const struct pf1550_desc *desc = container_of(rdev->desc,
- struct pf1550_desc,
- desc);
+ const struct pf1550_desc *desc = container_of_const(rdev->desc,
+ struct pf1550_desc,
+ desc);
return regmap_update_bits(rdev->regmap, desc->stby_enable_reg,
desc->stby_enable_mask, 0);
@@ -93,9 +93,9 @@ static int pf1550_set_suspend_disable(struct regulator_dev *rdev)
static int pf1550_buck_set_table_suspend_voltage(struct regulator_dev *rdev,
int uV)
{
- const struct pf1550_desc *desc = container_of(rdev->desc,
- struct pf1550_desc,
- desc);
+ const struct pf1550_desc *desc = container_of_const(rdev->desc,
+ struct pf1550_desc,
+ desc);
int ret;
ret = regulator_map_voltage_ascend(rdev, uV, uV);
@@ -111,9 +111,9 @@ static int pf1550_buck_set_table_suspend_voltage(struct regulator_dev *rdev,
static int pf1550_buck_set_linear_suspend_voltage(struct regulator_dev *rdev,
int uV)
{
- const struct pf1550_desc *desc = container_of(rdev->desc,
- struct pf1550_desc,
- desc);
+ const struct pf1550_desc *desc = container_of_const(rdev->desc,
+ struct pf1550_desc,
+ desc);
int ret;
ret = regulator_map_voltage_linear(rdev, uV, uV);
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 1/8] regulator: Use container_of_const() when all types are const
2025-11-26 16:58 ` [PATCH 1/8] " Krzysztof Kozlowski
@ 2025-11-26 17:33 ` Mark Brown
2025-11-26 17:37 ` Krzysztof Kozlowski
0 siblings, 1 reply; 13+ messages in thread
From: Mark Brown @ 2025-11-26 17:33 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Liam Girdwood, Bartosz Golaszewski, Matthias Brugger,
AngeloGioacchino Del Regno, Samuel Kayode, Matti Vaittinen,
linux-kernel, linux-arm-kernel, linux-mediatek, imx
[-- Attachment #1: Type: text/plain, Size: 312 bytes --]
On Wed, Nov 26, 2025 at 05:58:44PM +0100, Krzysztof Kozlowski wrote:
> Use container_of_const(), which is preferred over container_of(), when
> the argument 'ptr' and returned pointer are already const, for better
> code safety and readability.
This doesn't apply against current code, please check and resend.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/8] regulator: Use container_of_const() when all types are const
2025-11-26 17:33 ` Mark Brown
@ 2025-11-26 17:37 ` Krzysztof Kozlowski
2025-11-26 18:45 ` Mark Brown
0 siblings, 1 reply; 13+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 17:37 UTC (permalink / raw)
To: Mark Brown
Cc: Liam Girdwood, Bartosz Golaszewski, Matthias Brugger,
AngeloGioacchino Del Regno, Samuel Kayode, Matti Vaittinen,
linux-kernel, linux-arm-kernel, linux-mediatek, imx
On 26/11/2025 18:33, Mark Brown wrote:
> On Wed, Nov 26, 2025 at 05:58:44PM +0100, Krzysztof Kozlowski wrote:
>> Use container_of_const(), which is preferred over container_of(), when
>> the argument 'ptr' and returned pointer are already const, for better
>> code safety and readability.
>
> This doesn't apply against current code, please check and resend.
Apologies, I will rebase and send v2 today.
The files having trouble are I think in this pull:
https://lore.kernel.org/all/20251021172543.GL475031@google.com/
I will skip them for now.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/8] regulator: Use container_of_const() when all types are const
2025-11-26 17:37 ` Krzysztof Kozlowski
@ 2025-11-26 18:45 ` Mark Brown
0 siblings, 0 replies; 13+ messages in thread
From: Mark Brown @ 2025-11-26 18:45 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Liam Girdwood, Bartosz Golaszewski, Matthias Brugger,
AngeloGioacchino Del Regno, Samuel Kayode, Matti Vaittinen,
linux-kernel, linux-arm-kernel, linux-mediatek, imx
[-- Attachment #1: Type: text/plain, Size: 514 bytes --]
On Wed, Nov 26, 2025 at 06:37:49PM +0100, Krzysztof Kozlowski wrote:
> On 26/11/2025 18:33, Mark Brown wrote:
> > This doesn't apply against current code, please check and resend.
> Apologies, I will rebase and send v2 today.
> The files having trouble are I think in this pull:
> https://lore.kernel.org/all/20251021172543.GL475031@google.com/
Ah, no - that's it exactly. I've grabbed that PR and thrown your v1
into CI, I usually hold off on PRs until they're needed but there's no
problem with using them.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 2/8] regulator: bd71815: Constify pointers to 'regulator_desc' wrap struct
2025-11-26 16:58 [PATCH 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
2025-11-26 16:58 ` [PATCH 1/8] " Krzysztof Kozlowski
@ 2025-11-26 16:58 ` Krzysztof Kozlowski
2025-11-26 16:58 ` [PATCH 3/8] regulator: bd71828: " Krzysztof Kozlowski
` (6 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 16:58 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Bartosz Golaszewski, Matthias Brugger,
AngeloGioacchino Del Regno, Samuel Kayode, Matti Vaittinen
Cc: linux-kernel, linux-arm-kernel, linux-mediatek, imx,
Krzysztof Kozlowski
Pointer to 'struct regulator_desc' is a pointer to const and the
wrapping structure (container) is not being modified, thus entire syntax
can be replaced to preferred and safer container_of_const().
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
drivers/regulator/bd71815-regulator.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/regulator/bd71815-regulator.c b/drivers/regulator/bd71815-regulator.c
index 79fbb45297f6..8da57a7bb2f1 100644
--- a/drivers/regulator/bd71815-regulator.c
+++ b/drivers/regulator/bd71815-regulator.c
@@ -173,9 +173,9 @@ static int set_hw_dvs_levels(struct device_node *np,
const struct regulator_desc *desc,
struct regulator_config *cfg)
{
- struct bd71815_regulator *data;
+ const struct bd71815_regulator *data;
- data = container_of(desc, struct bd71815_regulator, desc);
+ data = container_of_const(desc, struct bd71815_regulator, desc);
return rohm_regulator_set_dvs_levels(data->dvs, np, desc, cfg->regmap);
}
@@ -195,10 +195,10 @@ static int buck12_set_hw_dvs_levels(struct device_node *np,
const struct regulator_desc *desc,
struct regulator_config *cfg)
{
- struct bd71815_regulator *data;
+ const struct bd71815_regulator *data;
int ret = 0, val;
- data = container_of(desc, struct bd71815_regulator, desc);
+ data = container_of_const(desc, struct bd71815_regulator, desc);
if (of_property_present(np, "rohm,dvs-run-voltage") ||
of_property_present(np, "rohm,dvs-suspend-voltage") ||
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH 3/8] regulator: bd71828: Constify pointers to 'regulator_desc' wrap struct
2025-11-26 16:58 [PATCH 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
2025-11-26 16:58 ` [PATCH 1/8] " Krzysztof Kozlowski
2025-11-26 16:58 ` [PATCH 2/8] regulator: bd71815: Constify pointers to 'regulator_desc' wrap struct Krzysztof Kozlowski
@ 2025-11-26 16:58 ` Krzysztof Kozlowski
2025-11-26 16:58 ` [PATCH 4/8] regulator: bd718x7: " Krzysztof Kozlowski
` (5 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 16:58 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Bartosz Golaszewski, Matthias Brugger,
AngeloGioacchino Del Regno, Samuel Kayode, Matti Vaittinen
Cc: linux-kernel, linux-arm-kernel, linux-mediatek, imx,
Krzysztof Kozlowski
Pointer to 'struct regulator_desc' is a pointer to const and the
wrapping structure (container) is not being modified, thus entire syntax
can be replaced to preferred and safer container_of_const().
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
drivers/regulator/bd71828-regulator.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/regulator/bd71828-regulator.c b/drivers/regulator/bd71828-regulator.c
index dd871ffe979c..87de87793fa1 100644
--- a/drivers/regulator/bd71828-regulator.c
+++ b/drivers/regulator/bd71828-regulator.c
@@ -95,9 +95,9 @@ static int buck_set_hw_dvs_levels(struct device_node *np,
const struct regulator_desc *desc,
struct regulator_config *cfg)
{
- struct bd71828_regulator_data *data;
+ const struct bd71828_regulator_data *data;
- data = container_of(desc, struct bd71828_regulator_data, desc);
+ data = container_of_const(desc, struct bd71828_regulator_data, desc);
return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap);
}
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH 4/8] regulator: bd718x7: Constify pointers to 'regulator_desc' wrap struct
2025-11-26 16:58 [PATCH 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
` (2 preceding siblings ...)
2025-11-26 16:58 ` [PATCH 3/8] regulator: bd71828: " Krzysztof Kozlowski
@ 2025-11-26 16:58 ` Krzysztof Kozlowski
2025-11-26 16:58 ` [PATCH 5/8] regulator: bd96801: " Krzysztof Kozlowski
` (4 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 16:58 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Bartosz Golaszewski, Matthias Brugger,
AngeloGioacchino Del Regno, Samuel Kayode, Matti Vaittinen
Cc: linux-kernel, linux-arm-kernel, linux-mediatek, imx,
Krzysztof Kozlowski
Pointer to 'struct regulator_desc' is a pointer to const and the
wrapping structure (container) is not being modified, thus entire syntax
can be replaced to preferred and safer container_of_const().
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
drivers/regulator/bd718x7-regulator.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/regulator/bd718x7-regulator.c b/drivers/regulator/bd718x7-regulator.c
index ea9c4058ee6a..1b5997c8482e 100644
--- a/drivers/regulator/bd718x7-regulator.c
+++ b/drivers/regulator/bd718x7-regulator.c
@@ -698,9 +698,9 @@ static int buck_set_hw_dvs_levels(struct device_node *np,
const struct regulator_desc *desc,
struct regulator_config *cfg)
{
- struct bd718xx_regulator_data *data;
+ const struct bd718xx_regulator_data *data;
- data = container_of(desc, struct bd718xx_regulator_data, desc);
+ data = container_of_const(desc, struct bd718xx_regulator_data, desc);
return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap);
}
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH 5/8] regulator: bd96801: Constify pointers to 'regulator_desc' wrap struct
2025-11-26 16:58 [PATCH 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
` (3 preceding siblings ...)
2025-11-26 16:58 ` [PATCH 4/8] regulator: bd718x7: " Krzysztof Kozlowski
@ 2025-11-26 16:58 ` Krzysztof Kozlowski
2025-11-26 16:58 ` [PATCH 6/8] regulator: mt6358: " Krzysztof Kozlowski
` (3 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 16:58 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Bartosz Golaszewski, Matthias Brugger,
AngeloGioacchino Del Regno, Samuel Kayode, Matti Vaittinen
Cc: linux-kernel, linux-arm-kernel, linux-mediatek, imx,
Krzysztof Kozlowski
Pointer to 'struct regulator_desc' is a pointer to const and the
wrapping structure (container) is not being modified, thus entire syntax
can be replaced to preferred and safer container_of_const().
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
drivers/regulator/bd96801-regulator.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/regulator/bd96801-regulator.c b/drivers/regulator/bd96801-regulator.c
index 24d21172298b..129b20c33bad 100644
--- a/drivers/regulator/bd96801-regulator.c
+++ b/drivers/regulator/bd96801-regulator.c
@@ -337,12 +337,12 @@ static int ldo_map_notif(int irq, struct regulator_irq_data *rid,
int i;
for (i = 0; i < rid->num_states; i++) {
- struct bd96801_regulator_data *rdata;
+ const struct bd96801_regulator_data *rdata;
struct regulator_dev *rdev;
rdev = rid->states[i].rdev;
- rdata = container_of(rdev->desc, struct bd96801_regulator_data,
- desc);
+ rdata = container_of_const(rdev->desc, struct bd96801_regulator_data,
+ desc);
rid->states[i].notifs = regulator_err2notif(rdata->ldo_errs);
rid->states[i].errors = rdata->ldo_errs;
*dev_mask |= BIT(i);
@@ -354,9 +354,9 @@ static int bd96801_list_voltage_lr(struct regulator_dev *rdev,
unsigned int selector)
{
int voltage;
- struct bd96801_regulator_data *data;
+ const struct bd96801_regulator_data *data;
- data = container_of(rdev->desc, struct bd96801_regulator_data, desc);
+ data = container_of_const(rdev->desc, struct bd96801_regulator_data, desc);
/*
* The BD096801 has voltage setting in two registers. One giving the
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH 6/8] regulator: mt6358: Constify pointers to 'regulator_desc' wrap struct
2025-11-26 16:58 [PATCH 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
` (4 preceding siblings ...)
2025-11-26 16:58 ` [PATCH 5/8] regulator: bd96801: " Krzysztof Kozlowski
@ 2025-11-26 16:58 ` Krzysztof Kozlowski
2025-11-26 16:58 ` [PATCH 7/8] regulator: pca9450: " Krzysztof Kozlowski
` (2 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 16:58 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Bartosz Golaszewski, Matthias Brugger,
AngeloGioacchino Del Regno, Samuel Kayode, Matti Vaittinen
Cc: linux-kernel, linux-arm-kernel, linux-mediatek, imx,
Krzysztof Kozlowski
Pointer to 'struct regulator_desc' is a pointer to const and the
wrapping structure (container) is not being modified, thus entire syntax
can be replaced to preferred and safer container_of_const().
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
drivers/regulator/mt6358-regulator.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/regulator/mt6358-regulator.c b/drivers/regulator/mt6358-regulator.c
index e4745f616cea..2604f674be49 100644
--- a/drivers/regulator/mt6358-regulator.c
+++ b/drivers/regulator/mt6358-regulator.c
@@ -31,7 +31,7 @@ struct mt6358_regulator_info {
u32 modeset_mask;
};
-#define to_regulator_info(x) container_of((x), struct mt6358_regulator_info, desc)
+#define to_regulator_info(x) container_of_const((x), struct mt6358_regulator_info, desc)
#define MT6358_BUCK(match, vreg, supply, min, max, step, \
vosel_mask, _da_vsel_reg, _da_vsel_mask, \
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH 7/8] regulator: pca9450: Constify pointers to 'regulator_desc' wrap struct
2025-11-26 16:58 [PATCH 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
` (5 preceding siblings ...)
2025-11-26 16:58 ` [PATCH 6/8] regulator: mt6358: " Krzysztof Kozlowski
@ 2025-11-26 16:58 ` Krzysztof Kozlowski
2025-11-26 16:58 ` [PATCH 8/8] regulator: pf9453: " Krzysztof Kozlowski
2025-11-26 22:05 ` [PATCH 0/8] regulator: Use container_of_const() when all types are const Mark Brown
8 siblings, 0 replies; 13+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 16:58 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Bartosz Golaszewski, Matthias Brugger,
AngeloGioacchino Del Regno, Samuel Kayode, Matti Vaittinen
Cc: linux-kernel, linux-arm-kernel, linux-mediatek, imx,
Krzysztof Kozlowski
Pointer to 'struct regulator_desc' is a pointer to const and the
wrapping structure (container) is not being modified, thus entire syntax
can be replaced to preferred and safer container_of_const().
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
drivers/regulator/pca9450-regulator.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/regulator/pca9450-regulator.c b/drivers/regulator/pca9450-regulator.c
index 32780c311ccd..5fa868264250 100644
--- a/drivers/regulator/pca9450-regulator.c
+++ b/drivers/regulator/pca9450-regulator.c
@@ -249,7 +249,7 @@ static int buck_set_dvs(const struct regulator_desc *desc,
}
if (ret == 0) {
- struct pca9450_regulator_desc *regulator = container_of(desc,
+ const struct pca9450_regulator_desc *regulator = container_of_const(desc,
struct pca9450_regulator_desc, desc);
/* Enable DVS control through PMIC_STBY_REQ for this BUCK */
@@ -263,7 +263,7 @@ static int pca9450_set_dvs_levels(struct device_node *np,
const struct regulator_desc *desc,
struct regulator_config *cfg)
{
- struct pca9450_regulator_desc *data = container_of(desc,
+ const struct pca9450_regulator_desc *data = container_of_const(desc,
struct pca9450_regulator_desc, desc);
const struct pc9450_dvs_config *dvs = &data->dvs;
unsigned int reg, mask;
@@ -308,7 +308,7 @@ static inline unsigned int pca9450_map_mode(unsigned int mode)
static int pca9450_buck_set_mode(struct regulator_dev *rdev, unsigned int mode)
{
- struct pca9450_regulator_desc *desc = container_of(rdev->desc,
+ const struct pca9450_regulator_desc *desc = container_of_const(rdev->desc,
struct pca9450_regulator_desc, desc);
const struct pc9450_dvs_config *dvs = &desc->dvs;
int val;
@@ -333,7 +333,7 @@ static int pca9450_buck_set_mode(struct regulator_dev *rdev, unsigned int mode)
static unsigned int pca9450_buck_get_mode(struct regulator_dev *rdev)
{
- struct pca9450_regulator_desc *desc = container_of(rdev->desc,
+ const struct pca9450_regulator_desc *desc = container_of_const(rdev->desc,
struct pca9450_regulator_desc, desc);
const struct pc9450_dvs_config *dvs = &desc->dvs;
int ret = 0, regval;
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH 8/8] regulator: pf9453: Constify pointers to 'regulator_desc' wrap struct
2025-11-26 16:58 [PATCH 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
` (6 preceding siblings ...)
2025-11-26 16:58 ` [PATCH 7/8] regulator: pca9450: " Krzysztof Kozlowski
@ 2025-11-26 16:58 ` Krzysztof Kozlowski
2025-11-26 22:05 ` [PATCH 0/8] regulator: Use container_of_const() when all types are const Mark Brown
8 siblings, 0 replies; 13+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 16:58 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Bartosz Golaszewski, Matthias Brugger,
AngeloGioacchino Del Regno, Samuel Kayode, Matti Vaittinen
Cc: linux-kernel, linux-arm-kernel, linux-mediatek, imx,
Krzysztof Kozlowski
Pointer to 'struct regulator_desc' is a pointer to const and the
wrapping structure (container) is not being modified, thus entire syntax
can be replaced to preferred and safer container_of_const().
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
drivers/regulator/pf9453-regulator.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/regulator/pf9453-regulator.c b/drivers/regulator/pf9453-regulator.c
index cdb80f9d1bd7..779a6fdb0574 100644
--- a/drivers/regulator/pf9453-regulator.c
+++ b/drivers/regulator/pf9453-regulator.c
@@ -538,7 +538,9 @@ static int buck_set_dvs(const struct regulator_desc *desc,
static int pf9453_set_dvs_levels(struct device_node *np, const struct regulator_desc *desc,
struct regulator_config *cfg)
{
- struct pf9453_regulator_desc *data = container_of(desc, struct pf9453_regulator_desc, desc);
+ const struct pf9453_regulator_desc *data = container_of_const(desc,
+ struct pf9453_regulator_desc,
+ desc);
struct pf9453 *pf9453 = dev_get_drvdata(cfg->dev);
const struct pf9453_dvs_config *dvs = &data->dvs;
unsigned int reg, mask;
--
2.48.1
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 0/8] regulator: Use container_of_const() when all types are const
2025-11-26 16:58 [PATCH 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
` (7 preceding siblings ...)
2025-11-26 16:58 ` [PATCH 8/8] regulator: pf9453: " Krzysztof Kozlowski
@ 2025-11-26 22:05 ` Mark Brown
8 siblings, 0 replies; 13+ messages in thread
From: Mark Brown @ 2025-11-26 22:05 UTC (permalink / raw)
To: Liam Girdwood, Bartosz Golaszewski, Matthias Brugger,
AngeloGioacchino Del Regno, Samuel Kayode, Matti Vaittinen,
Krzysztof Kozlowski
Cc: linux-kernel, linux-arm-kernel, linux-mediatek, imx
On Wed, 26 Nov 2025 17:58:43 +0100, Krzysztof Kozlowski wrote:
> Use container_of_const(), which is preferred over container_of(), when
> the argument 'ptr' and returned pointer are already const, for better
> code safety and readability.
>
> Some drivers already have const everywhere, so container_of_const can be
> directly used. In few other drivers, the final pointer can be constified
> that way.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next
Thanks!
[1/8] regulator: Use container_of_const() when all types are const
commit: ac1530cdea9846c6bff31827c0c4dffcbc186e6a
[2/8] regulator: bd71815: Constify pointers to 'regulator_desc' wrap struct
commit: 788915a22bdfde0925c074056056e7d408c242d0
[3/8] regulator: bd71828: Constify pointers to 'regulator_desc' wrap struct
commit: d02ea816cccae6c02c7c026b5a74bf99a784c9c8
[4/8] regulator: bd718x7: Constify pointers to 'regulator_desc' wrap struct
commit: 7a7e1ed307de6cc68639f602f3fa247ec0903354
[5/8] regulator: bd96801: Constify pointers to 'regulator_desc' wrap struct
commit: 50011cacaeb9556d65067ec8e757e3987ecf0f2b
[6/8] regulator: mt6358: Constify pointers to 'regulator_desc' wrap struct
commit: 438e90a287c86253dbb47e7fa43c4474f91ee7eb
[7/8] regulator: pca9450: Constify pointers to 'regulator_desc' wrap struct
commit: 03c3bdebaad23d6698a3cb8a11a915d8bdebf28f
[8/8] regulator: pf9453: Constify pointers to 'regulator_desc' wrap struct
commit: 6341646f7225343f57c8cbcb6a4d25b3270f4111
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 13+ messages in thread