mbox series

[0/8] clk: check memory returned by {devm_}kasprintf()

Message ID 20230530093913.1656095-1-claudiu.beznea@microchip.com
Headers show
Series clk: check memory returned by {devm_}kasprintf() | expand

Message

Claudiu Beznea May 30, 2023, 9:39 a.m. UTC
Hi,

While browsing some code I noticed that there are places where pointer
returned by devm_kasprintf() or kasprintf() is not checked. Thus I've
tooked the chance and fixed this (by updating kmerr.cocci script,
changes published at [1]). Along with it some other places where
resources may need to be freed on failure paths were updated.

Thank you,
Claudiu Beznea

[1] https://lore.kernel.org/all/20230530074044.1603426-1-claudiu.beznea@microchip.com/

Claudiu Beznea (8):
  clk: vc5: check memory returned by kasprintf()
  clk: cdce925: check return value of kasprintf()
  clk: si5341: return error if one synth clock registration fails
  clk: si5341: check return value of {devm_}kasprintf()
  clk: si5341: free unused memory on probe failure
  clk: keystone: sci-clk: check return value of kasprintf()
  clk: ti: clkctrl: check return value of kasprintf()
  clk: clocking-wizard: check return value of devm_kasprintf()

 drivers/clk/clk-cdce925.c                  | 12 +++++++
 drivers/clk/clk-si5341.c                   | 38 +++++++++++++---------
 drivers/clk/clk-versaclock5.c              | 29 +++++++++++++++++
 drivers/clk/keystone/sci-clk.c             |  2 ++
 drivers/clk/ti/clkctrl.c                   |  7 ++++
 drivers/clk/xilinx/clk-xlnx-clock-wizard.c |  5 +++
 6 files changed, 78 insertions(+), 15 deletions(-)

Comments

Stephen Boyd June 20, 2023, 6:53 p.m. UTC | #1
Quoting Claudiu Beznea (2023-05-30 02:39:06)
> kasprintf() returns a pointer to dynamically allocated memory.
> Pointer could be NULL in case allocation fails. Check pointer validity.
> Identified with coccinelle (kmerr.cocci script).
> 
> Fixes: f491276a5168 ("clk: vc5: Allow Versaclock driver to support multiple instances")
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---

Applied to clk-next
Stephen Boyd June 20, 2023, 6:54 p.m. UTC | #2
Quoting Claudiu Beznea (2023-05-30 02:39:09)
> {devm_}kasprintf() returns a pointer to dynamically allocated memory.
> Pointer could be NULL in case allocation fails. Check pointer validity.
> Identified with coccinelle (kmerr.cocci script).
> 
> Fixes: 3044a860fd09 ("clk: Add Si5341/Si5340 driver")
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---

Applied to clk-next
Stephen Boyd June 20, 2023, 6:55 p.m. UTC | #3
Quoting Claudiu Beznea (2023-05-30 02:39:10)
> Pointers from synth_clock_names[] should be freed at the end of probe
> either on probe success or failure path.
> 
> Fixes: b7bbf6ec4940 ("clk: si5341: Allow different output VDD_SEL values")
> Fixes: 9b13ff4340df ("clk: si5341: Add sysfs properties to allow checking/resetting device faults")
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---

Applied to clk-next
Stephen Boyd June 20, 2023, 6:55 p.m. UTC | #4
Quoting Claudiu Beznea (2023-05-30 02:39:11)
> kasprintf() returns a pointer to dynamically allocated memory.
> Pointer could be NULL in case allocation fails. Check pointer validity.
> Identified with coccinelle (kmerr.cocci script).
> 
> Fixes: b745c0794e2f ("clk: keystone: Add sci-clk driver support")
> Depends-on: 96488c09b0f4 ("clk: keystone: sci-clk: cut down the clock name length")
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---

Applied to clk-next