From: Claudiu Beznea <claudiu.beznea@microchip.com>
To: <mturquette@baylibre.com>, <sboyd@kernel.org>,
<luca.ceresoli@bootlin.com>, <nm@ti.com>, <kristo@kernel.org>,
<ssantosh@kernel.org>, <michal.simek@xilinx.com>
Cc: <aford173@gmail.com>, <mike.looijmans@topic.nl>,
<robert.hancock@calian.com>, <shawn.guo@linaro.org>,
<fabio.estevam@freescale.com>, <linux-clk@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-omap@vger.kernel.org>,
Claudiu Beznea <claudiu.beznea@microchip.com>
Subject: [PATCH 1/8] clk: vc5: check memory returned by kasprintf()
Date: Tue, 30 May 2023 12:39:06 +0300 [thread overview]
Message-ID: <20230530093913.1656095-2-claudiu.beznea@microchip.com> (raw)
In-Reply-To: <20230530093913.1656095-1-claudiu.beznea@microchip.com>
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>
---
drivers/clk/clk-versaclock5.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/drivers/clk/clk-versaclock5.c b/drivers/clk/clk-versaclock5.c
index fa71a57875ce..40fdf2564aa7 100644
--- a/drivers/clk/clk-versaclock5.c
+++ b/drivers/clk/clk-versaclock5.c
@@ -1028,6 +1028,11 @@ static int vc5_probe(struct i2c_client *client)
}
init.name = kasprintf(GFP_KERNEL, "%pOFn.mux", client->dev.of_node);
+ if (!init.name) {
+ ret = -ENOMEM;
+ goto err_clk;
+ }
+
init.ops = &vc5_mux_ops;
init.flags = 0;
init.parent_names = parent_names;
@@ -1042,6 +1047,10 @@ static int vc5_probe(struct i2c_client *client)
memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.dbl",
client->dev.of_node);
+ if (!init.name) {
+ ret = -ENOMEM;
+ goto err_clk;
+ }
init.ops = &vc5_dbl_ops;
init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names;
@@ -1057,6 +1066,10 @@ static int vc5_probe(struct i2c_client *client)
/* Register PFD */
memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.pfd", client->dev.of_node);
+ if (!init.name) {
+ ret = -ENOMEM;
+ goto err_clk;
+ }
init.ops = &vc5_pfd_ops;
init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names;
@@ -1074,6 +1087,10 @@ static int vc5_probe(struct i2c_client *client)
/* Register PLL */
memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.pll", client->dev.of_node);
+ if (!init.name) {
+ ret = -ENOMEM;
+ goto err_clk;
+ }
init.ops = &vc5_pll_ops;
init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names;
@@ -1093,6 +1110,10 @@ static int vc5_probe(struct i2c_client *client)
memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.fod%d",
client->dev.of_node, idx);
+ if (!init.name) {
+ ret = -ENOMEM;
+ goto err_clk;
+ }
init.ops = &vc5_fod_ops;
init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names;
@@ -1111,6 +1132,10 @@ static int vc5_probe(struct i2c_client *client)
memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.out0_sel_i2cb",
client->dev.of_node);
+ if (!init.name) {
+ ret = -ENOMEM;
+ goto err_clk;
+ }
init.ops = &vc5_clk_out_ops;
init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names;
@@ -1137,6 +1162,10 @@ static int vc5_probe(struct i2c_client *client)
memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.out%d",
client->dev.of_node, idx + 1);
+ if (!init.name) {
+ ret = -ENOMEM;
+ goto err_clk;
+ }
init.ops = &vc5_clk_out_ops;
init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names;
--
2.34.1
next prev parent reply other threads:[~2023-05-30 9:40 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-30 9:39 [PATCH 0/8] clk: check memory returned by {devm_}kasprintf() Claudiu Beznea
2023-05-30 9:39 ` Claudiu Beznea [this message]
2023-05-31 16:32 ` [PATCH 1/8] clk: vc5: check memory returned by kasprintf() Luca Ceresoli
2023-06-20 18:53 ` Stephen Boyd
2023-05-30 9:39 ` [PATCH 2/8] clk: cdce925: check return value of kasprintf() Claudiu Beznea
2023-06-20 18:54 ` Stephen Boyd
2023-05-30 9:39 ` [PATCH 3/8] clk: si5341: return error if one synth clock registration fails Claudiu Beznea
2023-06-20 18:54 ` Stephen Boyd
2023-05-30 9:39 ` [PATCH 4/8] clk: si5341: check return value of {devm_}kasprintf() Claudiu Beznea
2023-06-20 18:54 ` Stephen Boyd
2023-05-30 9:39 ` [PATCH 5/8] clk: si5341: free unused memory on probe failure Claudiu Beznea
2023-06-20 18:55 ` Stephen Boyd
2023-05-30 9:39 ` [PATCH 6/8] clk: keystone: sci-clk: check return value of kasprintf() Claudiu Beznea
2023-05-31 4:12 ` Tony Lindgren
2023-06-20 18:55 ` Stephen Boyd
2023-05-30 9:39 ` [PATCH 7/8] clk: ti: clkctrl: " Claudiu Beznea
2023-05-31 4:12 ` Tony Lindgren
2023-06-20 18:55 ` Stephen Boyd
2023-05-30 9:39 ` [PATCH 8/8] clk: clocking-wizard: check return value of devm_kasprintf() Claudiu Beznea
2023-06-20 18:55 ` Stephen Boyd
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230530093913.1656095-2-claudiu.beznea@microchip.com \
--to=claudiu.beznea@microchip.com \
--cc=aford173@gmail.com \
--cc=fabio.estevam@freescale.com \
--cc=kristo@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=michal.simek@xilinx.com \
--cc=mike.looijmans@topic.nl \
--cc=mturquette@baylibre.com \
--cc=nm@ti.com \
--cc=robert.hancock@calian.com \
--cc=sboyd@kernel.org \
--cc=shawn.guo@linaro.org \
--cc=ssantosh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®