diff mbox series

fpga: dfl: add missing platform_device_put in build_info_create_dev

Message ID 20201125065030.154074-1-miaoqinglang@huawei.com (mailing list archive)
State Not Applicable, archived
Headers show
Series fpga: dfl: add missing platform_device_put in build_info_create_dev | expand

Commit Message

Qinglang Miao Nov. 25, 2020, 6:50 a.m. UTC
platform_device_put is missing when it fails to set fdev->id. Set
a temp value to do sanity check.

Fixes: 543be3d8c999 ("fpga: add device feature list support")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
---
 drivers/fpga/dfl.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

kernel test robot Nov. 25, 2020, 9:22 a.m. UTC | #1
Hi Qinglang,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.10-rc5 next-20201124]
[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/Qinglang-Miao/fpga-dfl-add-missing-platform_device_put-in-build_info_create_dev/20201125-145159
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 127c501a03d5db8b833e953728d3bcf53c8832a9
config: arc-randconfig-m031-20201125 (attached as .config)
compiler: arc-elf-gcc (GCC) 9.3.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/86dbfca89da921d0c3c9682ea35cdb3b2e40e6be
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Qinglang-Miao/fpga-dfl-add-missing-platform_device_put-in-build_info_create_dev/20201125-145159
        git checkout 86dbfca89da921d0c3c9682ea35cdb3b2e40e6be
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arc 

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

All warnings (new ones prefixed by >>):

   drivers/fpga/dfl.c: In function 'build_info_create_dev':
>> drivers/fpga/dfl.c:880:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
     880 |  int tmp_id = dfl_id_alloc(type, &fdev->dev);
         |  ^~~

vim +880 drivers/fpga/dfl.c

   857	
   858	static int
   859	build_info_create_dev(struct build_feature_devs_info *binfo,
   860			      enum dfl_id_type type)
   861	{
   862		struct platform_device *fdev;
   863	
   864		if (type >= DFL_ID_MAX)
   865			return -EINVAL;
   866	
   867		/*
   868		 * we use -ENODEV as the initialization indicator which indicates
   869		 * whether the id need to be reclaimed
   870		 */
   871		fdev = platform_device_alloc(dfl_devs[type].name, -ENODEV);
   872		if (!fdev)
   873			return -ENOMEM;
   874	
   875		binfo->feature_dev = fdev;
   876		binfo->feature_num = 0;
   877	
   878		INIT_LIST_HEAD(&binfo->sub_features);
   879	
 > 880		int tmp_id = dfl_id_alloc(type, &fdev->dev);
   881		if (tmp_id < 0) {
   882			platform_device_put(fdev);
   883			return tmp_id;
   884		}
   885	
   886		fdev->id = tmp_id;
   887		fdev->dev.parent = &binfo->cdev->region->dev;
   888		fdev->dev.devt = dfl_get_devt(dfl_devs[type].devt_type, fdev->id);
   889	
   890		return 0;
   891	}
   892	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Wu, Hao Nov. 25, 2020, 10:06 a.m. UTC | #2
> Subject: [PATCH] fpga: dfl: add missing platform_device_put in
> build_info_create_dev
> 
> platform_device_put is missing when it fails to set fdev->id. Set
> a temp value to do sanity check.

will this case be covered already by build_info_free()?

Hao

> 
> Fixes: 543be3d8c999 ("fpga: add device feature list support")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
> ---
>  drivers/fpga/dfl.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
> index b450870b7..8958f0860 100644
> --- a/drivers/fpga/dfl.c
> +++ b/drivers/fpga/dfl.c
> @@ -877,10 +877,13 @@ build_info_create_dev(struct
> build_feature_devs_info *binfo,
> 
>  	INIT_LIST_HEAD(&binfo->sub_features);
> 
> -	fdev->id = dfl_id_alloc(type, &fdev->dev);
> -	if (fdev->id < 0)
> -		return fdev->id;
> +	int tmp_id = dfl_id_alloc(type, &fdev->dev);
> +	if (tmp_id < 0) {
> +		platform_device_put(fdev);
> +		return tmp_id;
> +	}
> 
> +	fdev->id = tmp_id;
>  	fdev->dev.parent = &binfo->cdev->region->dev;
>  	fdev->dev.devt = dfl_get_devt(dfl_devs[type].devt_type, fdev->id);
> 
> --
> 2.23.0
Qinglang Miao Nov. 26, 2020, 1:17 a.m. UTC | #3
在 2020/11/25 18:06, Wu, Hao 写道:
>> Subject: [PATCH] fpga: dfl: add missing platform_device_put in
>> build_info_create_dev
>>
>> platform_device_put is missing when it fails to set fdev->id. Set
>> a temp value to do sanity check.
> 
> will this case be covered already by build_info_free()?
> 
> Hao
Yes, you're right Hao.

build_info_create_dev is performed in parse_feature_list which follows
build_info_free.

So please ignore this patch.

Thanks!
> 
>>
>> Fixes: 543be3d8c999 ("fpga: add device feature list support")
>> Reported-by: Hulk Robot <hulkci@huawei.com>
>> Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
>> ---
>>   drivers/fpga/dfl.c | 9 ++++++---
>>   1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
>> index b450870b7..8958f0860 100644
>> --- a/drivers/fpga/dfl.c
>> +++ b/drivers/fpga/dfl.c
>> @@ -877,10 +877,13 @@ build_info_create_dev(struct
>> build_feature_devs_info *binfo,
>>
>>   	INIT_LIST_HEAD(&binfo->sub_features);
>>
>> -	fdev->id = dfl_id_alloc(type, &fdev->dev);
>> -	if (fdev->id < 0)
>> -		return fdev->id;
>> +	int tmp_id = dfl_id_alloc(type, &fdev->dev);
>> +	if (tmp_id < 0) {
>> +		platform_device_put(fdev);
>> +		return tmp_id;
>> +	}
>>
>> +	fdev->id = tmp_id;
>>   	fdev->dev.parent = &binfo->cdev->region->dev;
>>   	fdev->dev.devt = dfl_get_devt(dfl_devs[type].devt_type, fdev->id);
>>
>> --
>> 2.23.0
> 
> .
>
diff mbox series

Patch

diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c
index b450870b7..8958f0860 100644
--- a/drivers/fpga/dfl.c
+++ b/drivers/fpga/dfl.c
@@ -877,10 +877,13 @@  build_info_create_dev(struct build_feature_devs_info *binfo,
 
 	INIT_LIST_HEAD(&binfo->sub_features);
 
-	fdev->id = dfl_id_alloc(type, &fdev->dev);
-	if (fdev->id < 0)
-		return fdev->id;
+	int tmp_id = dfl_id_alloc(type, &fdev->dev);
+	if (tmp_id < 0) {
+		platform_device_put(fdev);
+		return tmp_id;
+	}
 
+	fdev->id = tmp_id;
 	fdev->dev.parent = &binfo->cdev->region->dev;
 	fdev->dev.devt = dfl_get_devt(dfl_devs[type].devt_type, fdev->id);