pwm changes for 6.8, take 2

The first commit fixes a duplicate cleanup in an error path introduced
 in pwm/for-6.8-rc1~13.
 
 The second cares for an out-of-bounds access. In practise it doesn't
 happen---otherwise someone would have noticed since v5.17-rc1 I
 guess---because the device tree binding for the two drivers using
 of_pwm_single_xlate() only have args->args_count == 1. A device-tree
 that doesn't conform to the respective bindings could trigger that
 easily however.
 
 The third and last one corrects the request callback of the jz4740 pwm
 driver which used dev_err_probe() long after .probe() completed. This is
 conceptually wrong because dev_err_probe() might call
 device_set_deferred_probe_reason() which is nonsensical after the driver
 is bound.
 -----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCgAdFiEEP4GsaTp6HlmJrf7Tj4D7WH0S/k4FAmWo3dwACgkQj4D7WH0S
 /k5L3Qf8Db1uwUEGFXjjMIS82djW6u8rAEu1bEVf0yqhFKB3zo/PO4b1bfTHvKGo
 SwSflvZ2UB+bcby1yIZTP1yUbDH1O3WFfxgYwdUR715us/iMCV5sYvuNagi0Fp8O
 edR1Ntr/CmaU5VeDyml7ZUIHj7oZ50hd1dvvEugvKQKEVvW8yHBR2OEuqI38cIyK
 ItsQPrN9ld7PXzE0UFWMJpi3lbo+Q4KEYbx0yzBmBGogLXi+nRCIGtMB5KzdUSvf
 K4mQPHDmUyHsviXyjXcywst7sL1ebUcI3FicvCf4by/Sek5jZQGtLoyRS0m4FkRw
 V/TQMiLhU5iKr84wPQUvw6ZYmcXxog==
 =BP0a
 -----END PGP SIGNATURE-----

Merge tag 'pwm/for-6.8-2' of gitolite.kernel.org:pub/scm/linux/kernel/git/ukleinek/linux

Pull pwm fixes from Uwe Kleine-König:

 - fix a duplicate cleanup in an error path introduced in
   this merge window

 - fix an out-of-bounds access

   In practise it doesn't happen - otherwise someone would have noticed
   since v5.17-rc1 I guess - because the device tree binding for the two
   drivers using of_pwm_single_xlate() only have args->args_count == 1.

   A device-tree that doesn't conform to the respective bindings could
   trigger that easily however.

 - correct the request callback of the jz4740 pwm driver which used
   dev_err_probe() long after .probe() completed.

   This is conceptually wrong because dev_err_probe() might call
   device_set_deferred_probe_reason() which is nonsensical after the
   driver is bound.

* tag 'pwm/for-6.8-2' of gitolite.kernel.org:pub/scm/linux/kernel/git/ukleinek/linux:
  pwm: jz4740: Don't use dev_err_probe() in .request()
  pwm: Fix out-of-bounds access in of_pwm_single_xlate()
  pwm: bcm2835: Remove duplicate call to clk_rate_exclusive_put()
This commit is contained in:
Linus Torvalds 2024-01-18 16:58:21 -08:00
commit 5c93506983
3 changed files with 6 additions and 7 deletions

View File

@ -152,7 +152,7 @@ of_pwm_single_xlate(struct pwm_chip *chip, const struct of_phandle_args *args)
pwm->args.period = args->args[0];
pwm->args.polarity = PWM_POLARITY_NORMAL;
if (args->args_count == 2 && args->args[2] & PWM_POLARITY_INVERTED)
if (args->args_count == 2 && args->args[1] & PWM_POLARITY_INVERTED)
pwm->args.polarity = PWM_POLARITY_INVERSED;
return pwm;

View File

@ -160,10 +160,8 @@ static int bcm2835_pwm_probe(struct platform_device *pdev)
ret = devm_add_action_or_reset(&pdev->dev, devm_clk_rate_exclusive_put,
pc->clk);
if (ret) {
clk_rate_exclusive_put(pc->clk);
if (ret)
return ret;
}
pc->rate = clk_get_rate(pc->clk);
if (!pc->rate)

View File

@ -61,9 +61,10 @@ static int jz4740_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
snprintf(name, sizeof(name), "timer%u", pwm->hwpwm);
clk = clk_get(chip->dev, name);
if (IS_ERR(clk))
return dev_err_probe(chip->dev, PTR_ERR(clk),
"Failed to get clock\n");
if (IS_ERR(clk)) {
dev_err(chip->dev, "error %pe: Failed to get clock\n", clk);
return PTR_ERR(clk);
}
err = clk_prepare_enable(clk);
if (err < 0) {