2021-12-17 12:09:16

by Jiasheng Jiang

[permalink] [raw]
Subject: [PATCH v2] isoc: mediatek: potential use of error pointer

The return value of devm_clk_get() needs to be checked.
To avoid use of error pointer in case of the failure of alloc.

Fixes: 6078c651947a ("soc: mediatek: Refine scpsys to support multiple platform")
Signed-off-by: Jiasheng Jiang <[email protected]>
---
Changelog:

v1 -> v2

*change 1. Change the "-ENOMEM" to "ERR_PTR(-ENOMEM)".
---
drivers/soc/mediatek/mtk-scpsys.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c
index ca75b14931ec..778d6ffc42b8 100644
--- a/drivers/soc/mediatek/mtk-scpsys.c
+++ b/drivers/soc/mediatek/mtk-scpsys.c
@@ -411,12 +411,16 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
return ret;
}

-static void init_clks(struct platform_device *pdev, struct clk **clk)
+static int init_clks(struct platform_device *pdev, struct clk **clk)
{
int i;

- for (i = CLK_NONE + 1; i < CLK_MAX; i++)
+ for (i = CLK_NONE + 1; i < CLK_MAX; i++) {
clk[i] = devm_clk_get(&pdev->dev, clk_names[i]);
+ if (!clk[i])
+ return ERR_PTR(-ENOMEM);
+ }
+ return 0;
}

static struct scp *init_scp(struct platform_device *pdev,
@@ -426,7 +430,7 @@ static struct scp *init_scp(struct platform_device *pdev,
{
struct genpd_onecell_data *pd_data;
struct resource *res;
- int i, j;
+ int i, j, ret;
struct scp *scp;
struct clk *clk[CLK_MAX];

@@ -481,7 +485,9 @@ static struct scp *init_scp(struct platform_device *pdev,

pd_data->num_domains = num;

- init_clks(pdev, clk);
+ ret = init_clks(pdev, clk);
+ if (ret)
+ return ERR_PTR(-ENOMEM);

for (i = 0; i < num; i++) {
struct scp_domain *scpd = &scp->domains[i];
--
2.25.1



2021-12-17 12:37:39

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v2] isoc: mediatek: potential use of error pointer

On Fri, Dec 17, 2021 at 08:08:45PM +0800, Jiasheng Jiang wrote:

> - for (i = CLK_NONE + 1; i < CLK_MAX; i++)
> + for (i = CLK_NONE + 1; i < CLK_MAX; i++) {
> clk[i] = devm_clk_get(&pdev->dev, clk_names[i]);
> + if (!clk[i])
> + return ERR_PTR(-ENOMEM);

That's not how to check the error code from clk_get(), still has the
problem with unconditionally using -ENOMEM. Please at least check that
the patches you are sending build...

Please submit patches using subject lines reflecting the style for the
subsystem, this makes it easier for people to identify relevant patches.
Look at what existing commits in the area you're changing are doing and
make sure your subject lines visually resemble what they're doing.
There's no need to resubmit to fix this alone.


Attachments:
(No filename) (770.00 B)
signature.asc (488.00 B)
Download all attachments

2021-12-17 14:07:19

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v2] isoc: mediatek: potential use of error pointer

Hi Jiasheng,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on broonie-sound/for-next]
[also build test WARNING on broonie-spi/for-next linus/master mbgg-mediatek/for-next v5.16-rc5 next-20211216]
[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]

url: https://github.com/0day-ci/linux/commits/Jiasheng-Jiang/isoc-mediatek-potential-use-of-error-pointer/20211217-201022
base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
config: mips-allyesconfig (https://download.01.org/0day-ci/archive/20211217/[email protected]/config)
compiler: mips-linux-gcc (GCC) 11.2.0
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
# https://github.com/0day-ci/linux/commit/1b5bac7d5052521b10c6c7ab2279cbd8c31cd458
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jiasheng-Jiang/isoc-mediatek-potential-use-of-error-pointer/20211217-201022
git checkout 1b5bac7d5052521b10c6c7ab2279cbd8c31cd458
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=mips SHELL=/bin/bash drivers/soc/mediatek/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

drivers/soc/mediatek/mtk-scpsys.c: In function 'init_clks':
>> drivers/soc/mediatek/mtk-scpsys.c:421:32: warning: returning 'void *' from a function with return type 'int' makes integer from pointer without a cast [-Wint-conversion]
421 | return ERR_PTR(-ENOMEM);
| ^~~~~~~~~~~~~~~~


vim +421 drivers/soc/mediatek/mtk-scpsys.c

413
414 static int init_clks(struct platform_device *pdev, struct clk **clk)
415 {
416 int i;
417
418 for (i = CLK_NONE + 1; i < CLK_MAX; i++) {
419 clk[i] = devm_clk_get(&pdev->dev, clk_names[i]);
420 if (!clk[i])
> 421 return ERR_PTR(-ENOMEM);
422 }
423 return 0;
424 }
425

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]