[PATCH v3] MIPS: BCM63xx: Add check for NULL for clk in clk_enable

Anastasia Belova posted 1 patch 2 years, 9 months ago
arch/mips/bcm63xx/clk.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH v3] MIPS: BCM63xx: Add check for NULL for clk in clk_enable
Posted by Anastasia Belova 2 years, 9 months ago
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>
---
v2: Fix errors reported by kernel test robot <lkp@intel.com>.
v3: Merge several patches into single one.
 arch/mips/bcm63xx/clk.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/mips/bcm63xx/clk.c b/arch/mips/bcm63xx/clk.c
index 6e6756e8fa0a..86a6e2590866 100644
--- a/arch/mips/bcm63xx/clk.c
+++ b/arch/mips/bcm63xx/clk.c
@@ -361,6 +361,8 @@ static struct clk clk_periph = {
  */
 int clk_enable(struct clk *clk)
 {
+	if (!clk)
+		return 0;
 	mutex_lock(&clocks_mutex);
 	clk_enable_unlocked(clk);
 	mutex_unlock(&clocks_mutex);
-- 
2.30.2
Re: [PATCH v3] MIPS: BCM63xx: Add check for NULL for clk in clk_enable
Posted by Thomas Bogendoerfer 2 years, 9 months ago
On Fri, Dec 09, 2022 at 01:05:50PM +0300, 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>
> ---
> v2: Fix errors reported by kernel test robot <lkp@intel.com>.
> v3: Merge several patches into single one.
>  arch/mips/bcm63xx/clk.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/mips/bcm63xx/clk.c b/arch/mips/bcm63xx/clk.c
> index 6e6756e8fa0a..86a6e2590866 100644
> --- a/arch/mips/bcm63xx/clk.c
> +++ b/arch/mips/bcm63xx/clk.c
> @@ -361,6 +361,8 @@ static struct clk clk_periph = {
>   */
>  int clk_enable(struct clk *clk)
>  {
> +	if (!clk)
> +		return 0;
>  	mutex_lock(&clocks_mutex);
>  	clk_enable_unlocked(clk);
>  	mutex_unlock(&clocks_mutex);
> -- 
> 2.30.2

applied to mips-next.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]
Re: [PATCH v3] MIPS: BCM63xx: Add check for NULL for clk in clk_enable
Posted by Florian Fainelli 2 years, 9 months ago
On 12/9/22 02:05, 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>

Acked-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian
Re: [PATCH v3] MIPS: BCM63xx: Add check for NULL for clk in clk_enable
Posted by Philippe Mathieu-Daudé 2 years, 9 months ago
On 9/12/22 11:05, 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>
> ---
> v2: Fix errors reported by kernel test robot <lkp@intel.com>.
> v3: Merge several patches into single one.
>   arch/mips/bcm63xx/clk.c | 2 ++
>   1 file changed, 2 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>