Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: Use container_of_const() when all types are const

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>
Link: https://patch.msgid.link/20251126-container-of-const-regulator-v1-1-eeec378144d4@oss.qualcomm.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Krzysztof Kozlowski and committed by
Mark Brown
ac1530cd a7d6255a

+28 -28
+5 -5
drivers/regulator/hi6421-regulator.c
··· 387 387 const struct hi6421_regulator_info *info; 388 388 unsigned int reg_val; 389 389 390 - info = container_of(rdev->desc, struct hi6421_regulator_info, desc); 390 + info = container_of_const(rdev->desc, struct hi6421_regulator_info, desc); 391 391 regmap_read(rdev->regmap, rdev->desc->enable_reg, &reg_val); 392 392 if (reg_val & info->mode_mask) 393 393 return REGULATOR_MODE_IDLE; ··· 400 400 const struct hi6421_regulator_info *info; 401 401 unsigned int reg_val; 402 402 403 - info = container_of(rdev->desc, struct hi6421_regulator_info, desc); 403 + info = container_of_const(rdev->desc, struct hi6421_regulator_info, desc); 404 404 regmap_read(rdev->regmap, rdev->desc->enable_reg, &reg_val); 405 405 if (reg_val & info->mode_mask) 406 406 return REGULATOR_MODE_STANDBY; ··· 414 414 const struct hi6421_regulator_info *info; 415 415 unsigned int new_mode; 416 416 417 - info = container_of(rdev->desc, struct hi6421_regulator_info, desc); 417 + info = container_of_const(rdev->desc, struct hi6421_regulator_info, desc); 418 418 switch (mode) { 419 419 case REGULATOR_MODE_NORMAL: 420 420 new_mode = 0; ··· 439 439 const struct hi6421_regulator_info *info; 440 440 unsigned int new_mode; 441 441 442 - info = container_of(rdev->desc, struct hi6421_regulator_info, desc); 442 + info = container_of_const(rdev->desc, struct hi6421_regulator_info, desc); 443 443 switch (mode) { 444 444 case REGULATOR_MODE_NORMAL: 445 445 new_mode = 0; ··· 464 464 { 465 465 const struct hi6421_regulator_info *info; 466 466 467 - info = container_of(rdev->desc, struct hi6421_regulator_info, desc); 467 + info = container_of_const(rdev->desc, struct hi6421_regulator_info, desc); 468 468 469 469 if (load_uA > info->eco_microamp) 470 470 return REGULATOR_MODE_NORMAL;
+2 -2
drivers/regulator/hi6421v530-regulator.c
··· 110 110 const struct hi6421v530_regulator_info *info; 111 111 unsigned int reg_val; 112 112 113 - info = container_of(rdev->desc, struct hi6421v530_regulator_info, rdesc); 113 + info = container_of_const(rdev->desc, struct hi6421v530_regulator_info, rdesc); 114 114 regmap_read(rdev->regmap, rdev->desc->enable_reg, &reg_val); 115 115 116 116 if (reg_val & (info->mode_mask)) ··· 125 125 const struct hi6421v530_regulator_info *info; 126 126 unsigned int new_mode; 127 127 128 - info = container_of(rdev->desc, struct hi6421v530_regulator_info, rdesc); 128 + info = container_of_const(rdev->desc, struct hi6421v530_regulator_info, rdesc); 129 129 switch (mode) { 130 130 case REGULATOR_MODE_NORMAL: 131 131 new_mode = 0;
+3 -3
drivers/regulator/hi6421v600-regulator.c
··· 121 121 const struct hi6421_spmi_reg_info *sreg; 122 122 unsigned int reg_val; 123 123 124 - sreg = container_of(rdev->desc, struct hi6421_spmi_reg_info, desc); 124 + sreg = container_of_const(rdev->desc, struct hi6421_spmi_reg_info, desc); 125 125 regmap_read(rdev->regmap, rdev->desc->enable_reg, &reg_val); 126 126 127 127 if (reg_val & sreg->eco_mode_mask) ··· 136 136 const struct hi6421_spmi_reg_info *sreg; 137 137 unsigned int val; 138 138 139 - sreg = container_of(rdev->desc, struct hi6421_spmi_reg_info, desc); 139 + sreg = container_of_const(rdev->desc, struct hi6421_spmi_reg_info, desc); 140 140 switch (mode) { 141 141 case REGULATOR_MODE_NORMAL: 142 142 val = 0; ··· 162 162 { 163 163 const struct hi6421_spmi_reg_info *sreg; 164 164 165 - sreg = container_of(rdev->desc, struct hi6421_spmi_reg_info, desc); 165 + sreg = container_of_const(rdev->desc, struct hi6421_spmi_reg_info, desc); 166 166 167 167 if (!sreg->eco_uA || ((unsigned int)load_uA > sreg->eco_uA)) 168 168 return REGULATOR_MODE_NORMAL;
+3 -3
drivers/regulator/max77650-regulator.c
··· 68 68 struct regmap *map; 69 69 int val, rv, en; 70 70 71 - rdesc = container_of(rdev->desc, struct max77650_regulator_desc, desc); 71 + rdesc = container_of_const(rdev->desc, struct max77650_regulator_desc, desc); 72 72 map = rdev_get_regmap(rdev); 73 73 74 74 rv = regmap_read(map, rdesc->regB, &val); ··· 85 85 const struct max77650_regulator_desc *rdesc; 86 86 struct regmap *map; 87 87 88 - rdesc = container_of(rdev->desc, struct max77650_regulator_desc, desc); 88 + rdesc = container_of_const(rdev->desc, struct max77650_regulator_desc, desc); 89 89 map = rdev_get_regmap(rdev); 90 90 91 91 return regmap_update_bits(map, rdesc->regB, ··· 98 98 const struct max77650_regulator_desc *rdesc; 99 99 struct regmap *map; 100 100 101 - rdesc = container_of(rdev->desc, struct max77650_regulator_desc, desc); 101 + rdesc = container_of_const(rdev->desc, struct max77650_regulator_desc, desc); 102 102 map = rdev_get_regmap(rdev); 103 103 104 104 return regmap_update_bits(map, rdesc->regB,
+3 -3
drivers/regulator/mt6315-regulator.c
··· 80 80 int ret, regval; 81 81 u32 modeset_mask; 82 82 83 - info = container_of(rdev->desc, struct mt6315_regulator_info, desc); 83 + info = container_of_const(rdev->desc, struct mt6315_regulator_info, desc); 84 84 modeset_mask = init->modeset_mask[rdev_get_id(rdev)]; 85 85 ret = regmap_read(rdev->regmap, MT6315_BUCK_TOP_4PHASE_ANA_CON42, &regval); 86 86 if (ret != 0) { ··· 111 111 int ret, val, curr_mode; 112 112 u32 modeset_mask; 113 113 114 - info = container_of(rdev->desc, struct mt6315_regulator_info, desc); 114 + info = container_of_const(rdev->desc, struct mt6315_regulator_info, desc); 115 115 modeset_mask = init->modeset_mask[rdev_get_id(rdev)]; 116 116 curr_mode = mt6315_regulator_get_mode(rdev); 117 117 switch (mode) { ··· 165 165 int ret; 166 166 u32 regval; 167 167 168 - info = container_of(rdev->desc, struct mt6315_regulator_info, desc); 168 + info = container_of_const(rdev->desc, struct mt6315_regulator_info, desc); 169 169 ret = regmap_read(rdev->regmap, info->status_reg, &regval); 170 170 if (ret < 0) { 171 171 dev_err(&rdev->dev, "Failed to get enable reg: %d\n", ret);
+12 -12
drivers/regulator/pf1550-regulator.c
··· 71 71 72 72 static int pf1550_set_suspend_enable(struct regulator_dev *rdev) 73 73 { 74 - const struct pf1550_desc *desc = container_of(rdev->desc, 75 - struct pf1550_desc, 76 - desc); 74 + const struct pf1550_desc *desc = container_of_const(rdev->desc, 75 + struct pf1550_desc, 76 + desc); 77 77 unsigned int val = desc->stby_enable_mask; 78 78 79 79 return regmap_update_bits(rdev->regmap, desc->stby_enable_reg, ··· 82 82 83 83 static int pf1550_set_suspend_disable(struct regulator_dev *rdev) 84 84 { 85 - const struct pf1550_desc *desc = container_of(rdev->desc, 86 - struct pf1550_desc, 87 - desc); 85 + const struct pf1550_desc *desc = container_of_const(rdev->desc, 86 + struct pf1550_desc, 87 + desc); 88 88 89 89 return regmap_update_bits(rdev->regmap, desc->stby_enable_reg, 90 90 desc->stby_enable_mask, 0); ··· 93 93 static int pf1550_buck_set_table_suspend_voltage(struct regulator_dev *rdev, 94 94 int uV) 95 95 { 96 - const struct pf1550_desc *desc = container_of(rdev->desc, 97 - struct pf1550_desc, 98 - desc); 96 + const struct pf1550_desc *desc = container_of_const(rdev->desc, 97 + struct pf1550_desc, 98 + desc); 99 99 int ret; 100 100 101 101 ret = regulator_map_voltage_ascend(rdev, uV, uV); ··· 111 111 static int pf1550_buck_set_linear_suspend_voltage(struct regulator_dev *rdev, 112 112 int uV) 113 113 { 114 - const struct pf1550_desc *desc = container_of(rdev->desc, 115 - struct pf1550_desc, 116 - desc); 114 + const struct pf1550_desc *desc = container_of_const(rdev->desc, 115 + struct pf1550_desc, 116 + desc); 117 117 int ret; 118 118 119 119 ret = regulator_map_voltage_linear(rdev, uV, uV);