mirror of https://github.com/torvalds/linux.git
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>
This commit is contained in:
parent
a7d6255a0b
commit
ac1530cdea
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue