Re: [PATCH] clk: vc5: Add memory check to prevent oops

From: Dan Carpenter
Date: Thu Jul 02 2020 - 10:45:21 EST


Hi Adam,

Thank you for the patch! Perhaps something to improve:

url: https://github.com/0day-ci/linux/commits/Adam-Ford/clk-vc5-Add-memory-check-to-prevent-oops/20200701-050451
base: https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-next
config: i386-randconfig-m021-20200701 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-14) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>

New smatch warnings:
drivers/clk/clk-versaclock5.c:818 vc5_get_output_config() error: uninitialized symbol 'np_output'.

# https://github.com/0day-ci/linux/commit/d445df5e4f918f08f66e20c366dc6c81dcdc8b57
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout d445df5e4f918f08f66e20c366dc6c81dcdc8b57
vim +/np_output +818 drivers/clk/clk-versaclock5.c

260249f929e81d Adam Ford 2020-06-03 783
260249f929e81d Adam Ford 2020-06-03 784 static int vc5_get_output_config(struct i2c_client *client,
260249f929e81d Adam Ford 2020-06-03 785 struct vc5_hw_data *clk_out)
260249f929e81d Adam Ford 2020-06-03 786 {
260249f929e81d Adam Ford 2020-06-03 787 struct device_node *np_output;
^^^^^^^^^

260249f929e81d Adam Ford 2020-06-03 788 char *child_name;
260249f929e81d Adam Ford 2020-06-03 789 int ret = 0;
260249f929e81d Adam Ford 2020-06-03 790
260249f929e81d Adam Ford 2020-06-03 791 child_name = kasprintf(GFP_KERNEL, "OUT%d", clk_out->num + 1);
d445df5e4f918f Adam Ford 2020-06-30 792 if (!child_name) {
d445df5e4f918f Adam Ford 2020-06-30 793 ret = -ENOMEM;
d445df5e4f918f Adam Ford 2020-06-30 794 goto output_error;
^^^^^^^^^^^^^^^^^^
Better to just return directly, because there is no clean up.

d445df5e4f918f Adam Ford 2020-06-30 795 }
260249f929e81d Adam Ford 2020-06-03 796 np_output = of_get_child_by_name(client->dev.of_node, child_name);
260249f929e81d Adam Ford 2020-06-03 797 kfree(child_name);
260249f929e81d Adam Ford 2020-06-03 798 if (!np_output)
d445df5e4f918f Adam Ford 2020-06-30 799 return 0;
260249f929e81d Adam Ford 2020-06-03 800
260249f929e81d Adam Ford 2020-06-03 801 ret = vc5_update_mode(np_output, clk_out);
260249f929e81d Adam Ford 2020-06-03 802 if (ret)
260249f929e81d Adam Ford 2020-06-03 803 goto output_error;
260249f929e81d Adam Ford 2020-06-03 804
260249f929e81d Adam Ford 2020-06-03 805 ret = vc5_update_power(np_output, clk_out);
260249f929e81d Adam Ford 2020-06-03 806 if (ret)
260249f929e81d Adam Ford 2020-06-03 807 goto output_error;
260249f929e81d Adam Ford 2020-06-03 808
260249f929e81d Adam Ford 2020-06-03 809 ret = vc5_update_slew(np_output, clk_out);
260249f929e81d Adam Ford 2020-06-03 810
260249f929e81d Adam Ford 2020-06-03 811 output_error:
260249f929e81d Adam Ford 2020-06-03 812 if (ret) {
260249f929e81d Adam Ford 2020-06-03 813 dev_err(&client->dev,
260249f929e81d Adam Ford 2020-06-03 814 "Invalid clock output configuration OUT%d\n",
260249f929e81d Adam Ford 2020-06-03 815 clk_out->num + 1);
260249f929e81d Adam Ford 2020-06-03 816 }
260249f929e81d Adam Ford 2020-06-03 817
260249f929e81d Adam Ford 2020-06-03 @818 of_node_put(np_output);
^^^^^^^^^
Uninitialized.

260249f929e81d Adam Ford 2020-06-03 819
260249f929e81d Adam Ford 2020-06-03 820 return ret;
260249f929e81d Adam Ford 2020-06-03 821 }
260249f929e81d Adam Ford 2020-06-03 822

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip