linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/8] regulator: Use container_of_const() when all types are const
@ 2025-11-26 17:40 Krzysztof Kozlowski
  2025-11-26 17:40 ` [PATCH v2 1/8] " Krzysztof Kozlowski
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 17:40 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

Changes in v2:
- Rebase on regulator/for-next, which does not have pf1550-regulator.c
  so drop this part.
- Link to v1: https://patch.msgid.link/20251126-container-of-const-regulator-v1-0-eeec378144d4@oss.qualcomm.com

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.

Best regards,
Krzysztof

---
Krzysztof Kozlowski (8):
      regulator: Use container_of_const() when all types are const
      regulator: bd71815: Constify pointers to 'regulator_desc' wrap struct
      regulator: bd71828: Constify pointers to 'regulator_desc' wrap struct
      regulator: bd718x7: Constify pointers to 'regulator_desc' wrap struct
      regulator: bd96801: Constify pointers to 'regulator_desc' wrap struct
      regulator: mt6358: Constify pointers to 'regulator_desc' wrap struct
      regulator: pca9450: Constify pointers to 'regulator_desc' wrap struct
      regulator: pf9453: Constify pointers to 'regulator_desc' wrap struct

 drivers/regulator/bd71815-regulator.c    |  8 ++++----
 drivers/regulator/bd71828-regulator.c    |  4 ++--
 drivers/regulator/bd718x7-regulator.c    |  4 ++--
 drivers/regulator/bd96801-regulator.c    | 10 +++++-----
 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/mt6358-regulator.c     |  2 +-
 drivers/regulator/pca9450-regulator.c    |  8 ++++----
 drivers/regulator/pf9453-regulator.c     |  4 +++-
 12 files changed, 37 insertions(+), 35 deletions(-)
---
base-commit: 35ed371beec9dbd889bf2ff2afd6cb549aa32805
change-id: 20251126-container-of-const-regulator-20e240c45b78

Best regards,
-- 
Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/8] regulator: Use container_of_const() when all types are const
  2025-11-26 17:40 [PATCH v2 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
@ 2025-11-26 17:40 ` Krzysztof Kozlowski
  2025-11-26 17:40 ` [PATCH v2 2/8] regulator: bd71815: Constify pointers to 'regulator_desc' wrap struct Krzysztof Kozlowski
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 17:40 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 +++---
 5 files changed, 16 insertions(+), 16 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, &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, &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, &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, &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, &regval);
 	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, &regval);
 	if (ret < 0) {
 		dev_err(&rdev->dev, "Failed to get enable reg: %d\n", ret);

-- 
2.48.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 2/8] regulator: bd71815: Constify pointers to 'regulator_desc' wrap struct
  2025-11-26 17:40 [PATCH v2 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
  2025-11-26 17:40 ` [PATCH v2 1/8] " Krzysztof Kozlowski
@ 2025-11-26 17:40 ` Krzysztof Kozlowski
  2025-11-26 17:40 ` [PATCH v2 3/8] regulator: bd71828: " Krzysztof Kozlowski
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 17:40 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] 10+ messages in thread

* [PATCH v2 3/8] regulator: bd71828: Constify pointers to 'regulator_desc' wrap struct
  2025-11-26 17:40 [PATCH v2 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
  2025-11-26 17:40 ` [PATCH v2 1/8] " Krzysztof Kozlowski
  2025-11-26 17:40 ` [PATCH v2 2/8] regulator: bd71815: Constify pointers to 'regulator_desc' wrap struct Krzysztof Kozlowski
@ 2025-11-26 17:40 ` Krzysztof Kozlowski
  2025-11-26 17:40 ` [PATCH v2 4/8] regulator: bd718x7: " Krzysztof Kozlowski
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 17:40 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] 10+ messages in thread

* [PATCH v2 4/8] regulator: bd718x7: Constify pointers to 'regulator_desc' wrap struct
  2025-11-26 17:40 [PATCH v2 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
                   ` (2 preceding siblings ...)
  2025-11-26 17:40 ` [PATCH v2 3/8] regulator: bd71828: " Krzysztof Kozlowski
@ 2025-11-26 17:40 ` Krzysztof Kozlowski
  2025-11-26 17:40 ` [PATCH v2 5/8] regulator: bd96801: " Krzysztof Kozlowski
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 17:40 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] 10+ messages in thread

* [PATCH v2 5/8] regulator: bd96801: Constify pointers to 'regulator_desc' wrap struct
  2025-11-26 17:40 [PATCH v2 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
                   ` (3 preceding siblings ...)
  2025-11-26 17:40 ` [PATCH v2 4/8] regulator: bd718x7: " Krzysztof Kozlowski
@ 2025-11-26 17:40 ` Krzysztof Kozlowski
  2025-11-26 17:40 ` [PATCH v2 6/8] regulator: mt6358: " Krzysztof Kozlowski
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 17:40 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] 10+ messages in thread

* [PATCH v2 6/8] regulator: mt6358: Constify pointers to 'regulator_desc' wrap struct
  2025-11-26 17:40 [PATCH v2 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
                   ` (4 preceding siblings ...)
  2025-11-26 17:40 ` [PATCH v2 5/8] regulator: bd96801: " Krzysztof Kozlowski
@ 2025-11-26 17:40 ` Krzysztof Kozlowski
  2025-11-26 17:40 ` [PATCH v2 7/8] regulator: pca9450: " Krzysztof Kozlowski
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 17:40 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] 10+ messages in thread

* [PATCH v2 7/8] regulator: pca9450: Constify pointers to 'regulator_desc' wrap struct
  2025-11-26 17:40 [PATCH v2 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
                   ` (5 preceding siblings ...)
  2025-11-26 17:40 ` [PATCH v2 6/8] regulator: mt6358: " Krzysztof Kozlowski
@ 2025-11-26 17:40 ` Krzysztof Kozlowski
  2025-11-26 17:40 ` [PATCH v2 8/8] regulator: pf9453: " Krzysztof Kozlowski
  2025-11-27  6:51 ` [PATCH v2 0/8] regulator: Use container_of_const() when all types are const Matti Vaittinen
  8 siblings, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 17:40 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] 10+ messages in thread

* [PATCH v2 8/8] regulator: pf9453: Constify pointers to 'regulator_desc' wrap struct
  2025-11-26 17:40 [PATCH v2 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
                   ` (6 preceding siblings ...)
  2025-11-26 17:40 ` [PATCH v2 7/8] regulator: pca9450: " Krzysztof Kozlowski
@ 2025-11-26 17:40 ` Krzysztof Kozlowski
  2025-11-27  6:51 ` [PATCH v2 0/8] regulator: Use container_of_const() when all types are const Matti Vaittinen
  8 siblings, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2025-11-26 17:40 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] 10+ messages in thread

* Re: [PATCH v2 0/8] regulator: Use container_of_const() when all types are const
  2025-11-26 17:40 [PATCH v2 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
                   ` (7 preceding siblings ...)
  2025-11-26 17:40 ` [PATCH v2 8/8] regulator: pf9453: " Krzysztof Kozlowski
@ 2025-11-27  6:51 ` Matti Vaittinen
  8 siblings, 0 replies; 10+ messages in thread
From: Matti Vaittinen @ 2025-11-27  6:51 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Liam Girdwood, Mark Brown,
	Bartosz Golaszewski, Matthias Brugger, AngeloGioacchino Del Regno,
	Samuel Kayode
  Cc: linux-kernel, linux-arm-kernel, linux-mediatek, imx

Thanks again Krzysztof! :)

On 26/11/2025 19:40, Krzysztof Kozlowski wrote:
> Changes in v2:
> - Rebase on regulator/for-next, which does not have pf1550-regulator.c
>    so drop this part.
> - Link to v1: https://patch.msgid.link/20251126-container-of-const-regulator-v1-0-eeec378144d4@oss.qualcomm.com
> 
> 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.
> 
> Best regards,
> Krzysztof
> 
> ---
> Krzysztof Kozlowski (8):

>        regulator: bd71815: Constify pointers to 'regulator_desc' wrap struct
>        regulator: bd71828: Constify pointers to 'regulator_desc' wrap struct
>        regulator: bd718x7: Constify pointers to 'regulator_desc' wrap struct
>        regulator: bd96801: Constify pointers to 'regulator_desc' wrap struct

For the above:
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>

Yours,
	-- Matti


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-11-27  6:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-26 17:40 [PATCH v2 0/8] regulator: Use container_of_const() when all types are const Krzysztof Kozlowski
2025-11-26 17:40 ` [PATCH v2 1/8] " Krzysztof Kozlowski
2025-11-26 17:40 ` [PATCH v2 2/8] regulator: bd71815: Constify pointers to 'regulator_desc' wrap struct Krzysztof Kozlowski
2025-11-26 17:40 ` [PATCH v2 3/8] regulator: bd71828: " Krzysztof Kozlowski
2025-11-26 17:40 ` [PATCH v2 4/8] regulator: bd718x7: " Krzysztof Kozlowski
2025-11-26 17:40 ` [PATCH v2 5/8] regulator: bd96801: " Krzysztof Kozlowski
2025-11-26 17:40 ` [PATCH v2 6/8] regulator: mt6358: " Krzysztof Kozlowski
2025-11-26 17:40 ` [PATCH v2 7/8] regulator: pca9450: " Krzysztof Kozlowski
2025-11-26 17:40 ` [PATCH v2 8/8] regulator: pf9453: " Krzysztof Kozlowski
2025-11-27  6:51 ` [PATCH v2 0/8] regulator: Use container_of_const() when all types are const Matti Vaittinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).