* [PATCH 1/3] pinctrl: ti: ti-iodelay: Fix some error handling paths
2024-07-09 20:37 [PATCH 0/3] pinctrl: ti: ti-iodelay: Fix some error handling paths + 2 unrelated clean-ups Christophe JAILLET
@ 2024-07-09 20:37 ` Christophe JAILLET
2024-07-09 20:37 ` [PATCH 2/3] pinctrl: ti: ti-iodelay: Constify struct ti_iodelay_reg_data Christophe JAILLET
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Christophe JAILLET @ 2024-07-09 20:37 UTC (permalink / raw)
To: linus.walleij, lokeshvutla, nm, robh, tony
Cc: linux-gpio, linux-kernel, kernel-janitors, Christophe JAILLET
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.
Fixes: 003910ebc83b ("pinctrl: Introduce TI IOdelay configuration driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
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(-)
diff --git a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
index f5e5a23d2226..451801acdc40 100644
--- a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
+++ b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
@@ -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,
--
2.45.2
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/3] pinctrl: ti: ti-iodelay: Constify struct ti_iodelay_reg_data
2024-07-09 20:37 [PATCH 0/3] pinctrl: ti: ti-iodelay: Fix some error handling paths + 2 unrelated clean-ups Christophe JAILLET
2024-07-09 20:37 ` [PATCH 1/3] pinctrl: ti: ti-iodelay: Fix some error handling paths Christophe JAILLET
@ 2024-07-09 20:37 ` Christophe JAILLET
2024-07-09 20:37 ` [PATCH 3/3] pinctrl: ti: ti-iodelay: Constify struct regmap_config Christophe JAILLET
2024-08-05 7:23 ` [PATCH 0/3] pinctrl: ti: ti-iodelay: Fix some error handling paths + 2 unrelated clean-ups Linus Walleij
3 siblings, 0 replies; 5+ messages in thread
From: Christophe JAILLET @ 2024-07-09 20:37 UTC (permalink / raw)
To: linus.walleij, lokeshvutla, nm, robh, tony
Cc: linux-gpio, linux-kernel, kernel-janitors, 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
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested-only.
---
drivers/pinctrl/ti/pinctrl-ti-iodelay.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
index 451801acdc40..65f9439d0d5b 100644
--- a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
+++ b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
@@ -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,
--
2.45.2
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 3/3] pinctrl: ti: ti-iodelay: Constify struct regmap_config
2024-07-09 20:37 [PATCH 0/3] pinctrl: ti: ti-iodelay: Fix some error handling paths + 2 unrelated clean-ups Christophe JAILLET
2024-07-09 20:37 ` [PATCH 1/3] pinctrl: ti: ti-iodelay: Fix some error handling paths Christophe JAILLET
2024-07-09 20:37 ` [PATCH 2/3] pinctrl: ti: ti-iodelay: Constify struct ti_iodelay_reg_data Christophe JAILLET
@ 2024-07-09 20:37 ` Christophe JAILLET
2024-08-05 7:23 ` [PATCH 0/3] pinctrl: ti: ti-iodelay: Fix some error handling paths + 2 unrelated clean-ups Linus Walleij
3 siblings, 0 replies; 5+ messages in thread
From: Christophe JAILLET @ 2024-07-09 20:37 UTC (permalink / raw)
To: linus.walleij, lokeshvutla, nm, robh, tony
Cc: linux-gpio, linux-kernel, kernel-janitors, 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
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested-only.
---
drivers/pinctrl/ti/pinctrl-ti-iodelay.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
index 65f9439d0d5b..019b302db2b0 100644
--- a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
+++ b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c
@@ -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,
--
2.45.2
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 0/3] pinctrl: ti: ti-iodelay: Fix some error handling paths + 2 unrelated clean-ups
2024-07-09 20:37 [PATCH 0/3] pinctrl: ti: ti-iodelay: Fix some error handling paths + 2 unrelated clean-ups Christophe JAILLET
` (2 preceding siblings ...)
2024-07-09 20:37 ` [PATCH 3/3] pinctrl: ti: ti-iodelay: Constify struct regmap_config Christophe JAILLET
@ 2024-08-05 7:23 ` Linus Walleij
3 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2024-08-05 7:23 UTC (permalink / raw)
To: Christophe JAILLET
Cc: lokeshvutla, nm, robh, tony, linux-gpio, linux-kernel,
kernel-janitors
On Tue, Jul 9, 2024 at 10:37 PM Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
> 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
Patches 1 & 2 applied, patch 3 was already contributed by
another developer.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 5+ messages in thread