pinctrl: ti: ti-iodelay: Fix some error handling paths + 2 unrelated clean-ups
Subsystems (3)
cover pinctrl: ti: ti-iodelay: Fix some error handling paths + 2 unrelated clean-ups
The first patch is completly speculative. It is based on static analysis when a function is called in the remove() function, but not in the error handling path of the probe.
When looking deeper at it, it seems that part of ti_iodelay_pinconf_init_dev() also needed to be fixed.
/!\ This is completly speculative. So review with care /!\
Patch 2 and 3 are just constification patches spoted while looking at the code.
Christophe JAILLET (3):
pinctrl: ti: ti-iodelay: Fix some error handling paths
pinctrl: ti: ti-iodelay: Constify struct ti_iodelay_reg_data
pinctrl: ti: ti-iodelay: Constify struct regmap_config
drivers/pinctrl/ti/pinctrl-ti-iodelay.c | 58 ++++++++++--------------- 1 file changed, 24 insertions(+), 34 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/3 pinctrl: ti: ti-iodelay: Fix some error handling paths
In the probe, if an error occurs after the ti_iodelay_pinconf_init_dev() call, it is likely that ti_iodelay_pinconf_deinit_dev() should be called, as already done in the remove function.
Also in ti_iodelay_pinconf_init_dev(), if an error occurs after the first regmap_update_bits() call, it is also likely that the deinit() function should be called.
The easier way to fix it is to add a devm_add_action_or_reset() at the rigtht place to have ti_iodelay_pinconf_deinit_dev() called when needed.
Doing so, the .remove() function can be removed, and the associated platform_set_drvdata() call in the probe as well.
---
Compile tested-only.
This patch is speculative, review with care!
--- drivers/pinctrl/ti/pinctrl-ti-iodelay.c | 52 ++++++++++--------------- 1 file changed, 21 insertions(+), 31 deletions(-)
drivers/pinctrl/ti/pinctrl-ti-iodelay.c +21 -31
@@ -273,6 +273,22 @@ static int ti_iodelay_pinconf_set(struct ti_iodelay_device *iod,return r; } +/** +* ti_iodelay_pinconf_deinit_dev() - deinit the iodelay device +* @data: IODelay device +* +* Deinitialize the IODelay device (basically just lock the region back up. +*/ +static void ti_iodelay_pinconf_deinit_dev (void *data) +{ +struct ti_iodelay_device *iod = data; +const struct ti_iodelay_reg_data *reg = iod->reg_data; + +/* lock the iodelay region back again */ +regmap_update_bits (iod->regmap, reg->reg_global_lock_offset, + reg->global_lock_mask, reg->global_lock_val); +} +/** * ti_iodelay_pinconf_init_dev() - Initialize IODelay device * @iod: iodelay device
@@ -295,6 +311,11 @@ static int ti_iodelay_pinconf_init_dev(struct ti_iodelay_device *iod)if (r)return r; + r =devm_add_action_or_reset (iod->dev, ti_iodelay_pinconf_deinit_dev, + iod); +if (r) +return r; +/* Read up Recalibration sequence done by bootloader */ r =regmap_read (iod->regmap, reg->reg_refclk_offset, &val);if (r)
@@ -353,21 +374,6 @@ static int ti_iodelay_pinconf_init_dev(struct ti_iodelay_device *iod)return 0 ; } -/** -* ti_iodelay_pinconf_deinit_dev() - deinit the iodelay device -* @iod: IODelay device -* -* Deinitialize the IODelay device (basically just lock the region back up. -*/ -static void ti_iodelay_pinconf_deinit_dev (struct ti_iodelay_device *iod) -{ -const struct ti_iodelay_reg_data *reg = iod->reg_data; - -/* lock the iodelay region back again */ -regmap_update_bits (iod->regmap, reg->reg_global_lock_offset, - reg->global_lock_mask, reg->global_lock_val); -} -/** * ti_iodelay_get_pingroup() - Find the group mapped by a group selector * @iod: iodelay device
@@ -877,27 +883,11 @@ static int ti_iodelay_probe(struct platform_device *pdev)return ret; } -platform_set_drvdata (pdev, iod); -return pinctrl_enable (iod->pctl); } -/** -* ti_iodelay_remove() - standard remove -* @pdev: platform device -*/ -static void ti_iodelay_remove (struct platform_device *pdev) -{ -struct ti_iodelay_device *iod =platform_get_drvdata (pdev); - -ti_iodelay_pinconf_deinit_dev (iod); - -/* Expect other allocations to be freed by devm */ -} -static struct platform_driver ti_iodelay_driver = { .probe = ti_iodelay_probe, - .remove_new = ti_iodelay_remove, .driver = { .name =DRIVER_NAME , .of_match_table = ti_iodelay_of_match,
Signature · 1 line
2.45.2
PATCH 2/3 pinctrl: ti: ti-iodelay: Constify struct ti_iodelay_reg_data
In reply to Christophe JAILLET'struct ti_iodelay_reg_data' is not modified in this driver.
Constifying this structure moves some data to a read-only section, so increase overall security.
On a x86_64, with allmodconfig:
Before:
======
text data bss dec hex filename
17259 1788 16 19063 4a77 drivers/pinctrl/ti/pinctrl-ti-iodelay.o
After:
=====
text data bss dec hex filename
17355 1692 16 19063 4a77 drivers/pinctrl/ti/pinctrl-ti-iodelay.o
---
Compile tested-only.
--- drivers/pinctrl/ti/pinctrl-ti-iodelay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/ti/pinctrl-ti-iodelay.c +1 -1
@@ -783,7 +783,7 @@ static struct regmap_config dra7_iodelay_regmap_config = { .max_register = 0xd1c, }; -static struct ti_iodelay_reg_data dra7_iodelay_data = { +static const struct ti_iodelay_reg_data dra7_iodelay_data = { .signature_mask =0x0003f000 , .signature_value =0x29 , .lock_mask =0x00000400 ,
Signature · 1 line
2.45.2
PATCH 3/3 pinctrl: ti: ti-iodelay: Constify struct regmap_config
In reply to Christophe JAILLET'struct regmap_config' is not modified in this driver.
Constifying this structure moves some data to a read-only section, so increase overall security.
On a x86_64, with allmodconfig:
Before:
======
text data bss dec hex filename
17355 1692 16 19063 4a77 drivers/pinctrl/ti/pinctrl-ti-iodelay.o
After:
=====
text data bss dec hex filename
17729 1372 16 19117 4aad drivers/pinctrl/ti/pinctrl-ti-iodelay.o
---
Compile tested-only.
--- drivers/pinctrl/ti/pinctrl-ti-iodelay.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pinctrl/ti/pinctrl-ti-iodelay.c +2 -2
@@ -82,7 +82,7 @@ struct ti_iodelay_reg_data {u32 reg_start_offset;u32 reg_nr_per_pin; -struct regmap_config *regmap_config; +const struct regmap_config *regmap_config; };/**
@@ -776,7 +776,7 @@ static int ti_iodelay_alloc_pins(struct device *dev,return 0 ; } -static struct regmap_config dra7_iodelay_regmap_config = { +static const struct regmap_config dra7_iodelay_regmap_config = { .reg_bits =32 , .reg_stride =4 , .val_bits =32 ,
Signature · 1 line
2.45.2
Quoted 9 lines · Christophe JAILLET
The first patch is completly speculative. It is based on static analysis when a function is called in the
remove()function, but not in the error handling path of the probe.
When looking deeper at it, it seems that part ofti_iodelay_pinconf_init_dev()also needed to be fixed./!\ This is completly speculative. So review with care /!\
Quoted 7 lines
Patch 2 and 3 are just constification patches spoted while looking at the code.
Christophe JAILLET (3):
pinctrl: ti: ti-iodelay: Fix some error handling paths
pinctrl: ti: ti-iodelay: Constify structti_iodelay_reg_data
pinctrl: ti: ti-iodelay: Constify structregmap_config
Patches 1 & 2 applied, patch 3 was already contributed by another developer.
Yours,
Linus Walleij