arch/arm/mach-ep93xx/clock.c:154:2: warning: Use of memory after it is freed [clang-analyzer-unix.Malloc]

From: kernel test robot
Date: Wed Jan 19 2022 - 20:47:41 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 1d1df41c5a33359a00e919d54eaebfb789711fdc
commit: 9645ccc7bd7a16cd73c3be9dee70cd702b03be37 ep93xx: clock: convert in-place to COMMON_CLK
date: 3 months ago
config: arm-randconfig-c002-20220118 (https://download.01.org/0day-ci/archive/20220120/202201200359.lTk9zHg4-lkp@xxxxxxxxx/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 5f782d25a742302d25ef3c8b84b54f7483c2deb9)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm cross compiling tool for clang build
# apt-get install binutils-arm-linux-gnueabi
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9645ccc7bd7a16cd73c3be9dee70cd702b03be37
git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git fetch --no-tags linus master
git checkout 9645ccc7bd7a16cd73c3be9dee70cd702b03be37
# save the config file to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm clang-analyzer

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


clang-analyzer warnings: (new ones prefixed by >>)

>> arch/arm/mach-ep93xx/clock.c:154:2: warning: Use of memory after it is freed [clang-analyzer-unix.Malloc]
return &psc->hw;
^
arch/arm/mach-ep93xx/clock.c:151:2: note: Taking true branch
if (IS_ERR(clk))
^
arch/arm/mach-ep93xx/clock.c:152:3: note: Memory is released
kfree(psc);
^~~~~~~~~~
arch/arm/mach-ep93xx/clock.c:154:2: note: Use of memory after it is freed
return &psc->hw;
^ ~~~~~~~~
>> arch/arm/mach-ep93xx/clock.c:484:2: warning: Value stored to 'hw' is never read [clang-analyzer-deadcode.DeadStores]
hw = clk_hw_register_fixed_factor(NULL, "uart", "xtali", 0, 1, clk_uart_div);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> arch/arm/mach-ep93xx/clock.c:612:2: warning: Value stored to 'hw' is never read [clang-analyzer-deadcode.DeadStores]
hw = clk_hw_register_fixed_factor(NULL, "usb_clk", "pll2", 0, 1, clk_usb_div);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

vim +154 arch/arm/mach-ep93xx/clock.c

ff05c0330b9880 Hartley Sweeten 2009-05-07 125
9645ccc7bd7a16 Nikita Shubin 2021-10-18 126 static struct clk_hw *ep93xx_clk_register_gate(const char *name,
9645ccc7bd7a16 Nikita Shubin 2021-10-18 127 const char *parent_name,
9645ccc7bd7a16 Nikita Shubin 2021-10-18 128 void __iomem *reg,
9645ccc7bd7a16 Nikita Shubin 2021-10-18 129 u8 bit_idx)
9645ccc7bd7a16 Nikita Shubin 2021-10-18 130 {
9645ccc7bd7a16 Nikita Shubin 2021-10-18 131 struct clk_init_data init;
9645ccc7bd7a16 Nikita Shubin 2021-10-18 132 struct clk_psc *psc;
9645ccc7bd7a16 Nikita Shubin 2021-10-18 133 struct clk *clk;
9645ccc7bd7a16 Nikita Shubin 2021-10-18 134
9645ccc7bd7a16 Nikita Shubin 2021-10-18 135 psc = kzalloc(sizeof(*psc), GFP_KERNEL);
9645ccc7bd7a16 Nikita Shubin 2021-10-18 136 if (!psc)
9645ccc7bd7a16 Nikita Shubin 2021-10-18 137 return ERR_PTR(-ENOMEM);
9645ccc7bd7a16 Nikita Shubin 2021-10-18 138
9645ccc7bd7a16 Nikita Shubin 2021-10-18 139 init.name = name;
9645ccc7bd7a16 Nikita Shubin 2021-10-18 140 init.ops = &clk_ep93xx_gate_ops;
9645ccc7bd7a16 Nikita Shubin 2021-10-18 141 init.flags = CLK_SET_RATE_PARENT;
9645ccc7bd7a16 Nikita Shubin 2021-10-18 142 init.parent_names = (parent_name ? &parent_name : NULL);
9645ccc7bd7a16 Nikita Shubin 2021-10-18 143 init.num_parents = (parent_name ? 1 : 0);
9645ccc7bd7a16 Nikita Shubin 2021-10-18 144
9645ccc7bd7a16 Nikita Shubin 2021-10-18 145 psc->reg = reg;
9645ccc7bd7a16 Nikita Shubin 2021-10-18 146 psc->bit_idx = bit_idx;
9645ccc7bd7a16 Nikita Shubin 2021-10-18 147 psc->hw.init = &init;
9645ccc7bd7a16 Nikita Shubin 2021-10-18 148 psc->lock = &clk_lock;
9645ccc7bd7a16 Nikita Shubin 2021-10-18 149
9645ccc7bd7a16 Nikita Shubin 2021-10-18 150 clk = clk_register(NULL, &psc->hw);
9645ccc7bd7a16 Nikita Shubin 2021-10-18 151 if (IS_ERR(clk))
9645ccc7bd7a16 Nikita Shubin 2021-10-18 152 kfree(psc);
9645ccc7bd7a16 Nikita Shubin 2021-10-18 153
9645ccc7bd7a16 Nikita Shubin 2021-10-18 @154 return &psc->hw;
ff05c0330b9880 Hartley Sweeten 2009-05-07 155 }
ff05c0330b9880 Hartley Sweeten 2009-05-07 156

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