MIPS: BCM63xx: Add check for NULL for clk in clk_enable

Message ID 20221125092601.3703-1-abelova@astralinux.ru
State New
Headers
Series MIPS: BCM63xx: Add check for NULL for clk in clk_enable |

Commit Message

Anastasia Belova Nov. 25, 2022, 9:26 a.m. UTC
  Check clk for NULL before calling clk_enable_unlocked where clk
is dereferenced. There is such check in other implementations
of clk_enable.

Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: e7300d04bd08 ("MIPS: BCM63xx: Add support for the Broadcom BCM63xx family of SOCs.")
Signed-off-by: Anastasia Belova <abelova@astralinux.ru>
---
 arch/mips/bcm63xx/clk.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Jonas Gorski Nov. 25, 2022, 2:14 p.m. UTC | #1
On Fri, 25 Nov 2022 at 10:28, Anastasia Belova <abelova@astralinux.ru> wrote:
>
> Check clk for NULL before calling clk_enable_unlocked where clk
> is dereferenced. There is such check in other implementations
> of clk_enable.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> Fixes: e7300d04bd08 ("MIPS: BCM63xx: Add support for the Broadcom BCM63xx family of SOCs.")
> Signed-off-by: Anastasia Belova <abelova@astralinux.ru>
> ---
>  arch/mips/bcm63xx/clk.c | 3 +++
>  1 file changed, 3 insertions(+)

Makes sense, especially since clk_disable() already has a NULL check
(in case anybody else wonders).

Reviewed-by: Jonas Gorski <jonas.gorski@gmail.com>
  
Philippe Mathieu-Daudé Nov. 25, 2022, 5:43 p.m. UTC | #2
On 25/11/22 10:26, Anastasia Belova wrote:
> Check clk for NULL before calling clk_enable_unlocked where clk
> is dereferenced. There is such check in other implementations
> of clk_enable.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> Fixes: e7300d04bd08 ("MIPS: BCM63xx: Add support for the Broadcom BCM63xx family of SOCs.")
> Signed-off-by: Anastasia Belova <abelova@astralinux.ru>
> ---
>   arch/mips/bcm63xx/clk.c | 3 +++
>   1 file changed, 3 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
  
Florian Fainelli Nov. 27, 2022, 8:29 p.m. UTC | #3
On 11/25/2022 1:26 AM, Anastasia Belova wrote:
> Check clk for NULL before calling clk_enable_unlocked where clk
> is dereferenced. There is such check in other implementations
> of clk_enable.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> Fixes: e7300d04bd08 ("MIPS: BCM63xx: Add support for the Broadcom BCM63xx family of SOCs.")
> Signed-off-by: Anastasia Belova <abelova@astralinux.ru>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
  
kernel test robot Nov. 30, 2022, 3:14 p.m. UTC | #4
Hi Anastasia,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.1-rc7 next-20221130]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Anastasia-Belova/MIPS-BCM63xx-Add-check-for-NULL-for-clk-in-clk_enable/20221125-173305
patch link:    https://lore.kernel.org/r/20221125092601.3703-1-abelova%40astralinux.ru
patch subject: [PATCH] MIPS: BCM63xx: Add check for NULL for clk in clk_enable
config: mips-buildonly-randconfig-r002-20221128
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 6e4cea55f0d1104408b26ac574566a0e4de48036)
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 mips cross compiling tool for clang build
        # apt-get install binutils-mips-linux-gnu
        # https://github.com/intel-lab-lkp/linux/commit/881e6b8fb4e5b8a496f5083d3cc6873a3df339b4
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Anastasia-Belova/MIPS-BCM63xx-Add-check-for-NULL-for-clk-in-clk_enable/20221125-173305
        git checkout 881e6b8fb4e5b8a496f5083d3cc6873a3df339b4
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=mips SHELL=/bin/bash arch/mips/bcm63xx/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> arch/mips/bcm63xx/clk.c:365:3: error: non-void function 'clk_enable' should return a value [-Wreturn-type]
                   return;
                   ^
   1 error generated.


vim +/clk_enable +365 arch/mips/bcm63xx/clk.c

   357	
   358	
   359	/*
   360	 * Linux clock API implementation
   361	 */
   362	int clk_enable(struct clk *clk)
   363	{
   364		if (!clk)
 > 365			return;
   366	
   367		mutex_lock(&clocks_mutex);
   368		clk_enable_unlocked(clk);
   369		mutex_unlock(&clocks_mutex);
   370		return 0;
   371	}
   372
  

Patch

diff --git a/arch/mips/bcm63xx/clk.c b/arch/mips/bcm63xx/clk.c
index 6e6756e8fa0a..401140cf36d9 100644
--- a/arch/mips/bcm63xx/clk.c
+++ b/arch/mips/bcm63xx/clk.c
@@ -361,6 +361,9 @@  static struct clk clk_periph = {
  */
 int clk_enable(struct clk *clk)
 {
+	if (!clk)
+		return;
+
 	mutex_lock(&clocks_mutex);
 	clk_enable_unlocked(clk);
 	mutex_unlock(&clocks_mutex);