diff mbox series

[3/3] HID: nvidia-shield: Introduce thunderstrike_destroy()

Message ID 4c9a8c7f6b4eb879dd7ef4d44bb6a80b3f126d25.1693070958.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State New
Delegated to: Jiri Kosina
Headers show
Series HID: nvidia-shield: Fix the error handling path of shield_probe() | expand

Commit Message

Christophe JAILLET Aug. 26, 2023, 5:42 p.m. UTC
In order to simplify some error handling paths, and avoid code duplication
introduce thunderstrike_destroy() which undoes thunderstrike_create().

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/hid/hid-nvidia-shield.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

Comments

kernel test robot Aug. 26, 2023, 8 p.m. UTC | #1
Hi Christophe,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linux-next/master]
[cannot apply to linus/master v6.5-rc7]
[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/Christophe-JAILLET/HID-nvidia-shield-Fix-a-missing-led_classdev_unregister-in-the-probe-error-handling-path/20230827-014602
base:   linux-next/master
patch link:    https://lore.kernel.org/r/4c9a8c7f6b4eb879dd7ef4d44bb6a80b3f126d25.1693070958.git.christophe.jaillet%40wanadoo.fr
patch subject: [PATCH 3/3] HID: nvidia-shield: Introduce thunderstrike_destroy()
config: parisc-allyesconfig (https://download.01.org/0day-ci/archive/20230827/202308270307.EDe7t62T-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 13.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230827/202308270307.EDe7t62T-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202308270307.EDe7t62T-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/hid/hid-nvidia-shield.c: In function 'shield_probe':
>> drivers/hid/hid-nvidia-shield.c:1046:31: warning: variable 'ts' set but not used [-Wunused-but-set-variable]
    1046 |         struct thunderstrike *ts;
         |                               ^~


vim +/ts +1046 drivers/hid/hid-nvidia-shield.c

09308562d4afb1a Rahul Rameshbabu   2023-06-08  1042  
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1043  static int shield_probe(struct hid_device *hdev, const struct hid_device_id *id)
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1044  {
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1045  	struct shield_device *shield_dev = NULL;
09308562d4afb1a Rahul Rameshbabu   2023-06-08 @1046  	struct thunderstrike *ts;
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1047  	int ret;
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1048  
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1049  	ret = hid_parse(hdev);
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1050  	if (ret) {
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1051  		hid_err(hdev, "Parse failed\n");
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1052  		return ret;
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1053  	}
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1054  
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1055  	switch (id->product) {
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1056  	case USB_DEVICE_ID_NVIDIA_THUNDERSTRIKE_CONTROLLER:
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1057  		shield_dev = thunderstrike_create(hdev);
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1058  		break;
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1059  	}
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1060  
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1061  	if (unlikely(!shield_dev)) {
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1062  		hid_err(hdev, "Failed to identify SHIELD device\n");
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1063  		return -ENODEV;
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1064  	}
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1065  	if (IS_ERR(shield_dev)) {
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1066  		hid_err(hdev, "Failed to create SHIELD device\n");
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1067  		return PTR_ERR(shield_dev);
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1068  	}
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1069  
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1070  	ts = container_of(shield_dev, struct thunderstrike, base);
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1071  
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1072  	ret = hid_hw_start(hdev, HID_CONNECT_HIDINPUT);
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1073  	if (ret) {
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1074  		hid_err(hdev, "Failed to start HID device\n");
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1075  		goto err_haptics;
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1076  	}
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1077  
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1078  	ret = hid_hw_open(hdev);
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1079  	if (ret) {
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1080  		hid_err(hdev, "Failed to open HID device\n");
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1081  		goto err_stop;
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1082  	}
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1083  
3ab196f882377ed Rahul Rameshbabu   2023-08-07  1084  	thunderstrike_device_init_info(shield_dev);
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1085  
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1086  	return ret;
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1087  
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1088  err_stop:
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1089  	hid_hw_stop(hdev);
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1090  err_haptics:
2cc4637842495c6 Christophe JAILLET 2023-08-26  1091  	thunderstrike_destroy(hdev);
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1092  	return ret;
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1093  }
09308562d4afb1a Rahul Rameshbabu   2023-06-08  1094
Christophe JAILLET Aug. 26, 2023, 9:13 p.m. UTC | #2
Le 26/08/2023 à 22:00, kernel test robot a écrit :
> Hi Christophe,
> 
> kernel test robot noticed the following build warnings:
> 
> [auto build test WARNING on linux-next/master]
> [cannot apply to linus/master v6.5-rc7]
> [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/Christophe-JAILLET/HID-nvidia-shield-Fix-a-missing-led_classdev_unregister-in-the-probe-error-handling-path/20230827-014602
> base:   linux-next/master
> patch link:    https://lore.kernel.org/r/4c9a8c7f6b4eb879dd7ef4d44bb6a80b3f126d25.1693070958.git.christophe.jaillet%40wanadoo.fr
> patch subject: [PATCH 3/3] HID: nvidia-shield: Introduce thunderstrike_destroy()
> config: parisc-allyesconfig (https://download.01.org/0day-ci/archive/20230827/202308270307.EDe7t62T-lkp@intel.com/config)
> compiler: hppa-linux-gcc (GCC) 13.2.0

On x86_64, gcc 12.3.0 does not complain. :(

Let see first if there is some comment on the serie, then I'll send a v2 
to fix the warning.

CJ

> reproduce: (https://download.01.org/0day-ci/archive/20230827/202308270307.EDe7t62T-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202308270307.EDe7t62T-lkp@intel.com/
> 
> All warnings (new ones prefixed by >>):
> 
>     drivers/hid/hid-nvidia-shield.c: In function 'shield_probe':
>>> drivers/hid/hid-nvidia-shield.c:1046:31: warning: variable 'ts' set but not used [-Wunused-but-set-variable]
>      1046 |         struct thunderstrike *ts;
>           |                               ^~
> 
> 
> vim +/ts +1046 drivers/hid/hid-nvidia-shield.c
> 
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1042
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1043  static int shield_probe(struct hid_device *hdev, const struct hid_device_id *id)
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1044  {
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1045  	struct shield_device *shield_dev = NULL;
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08 @1046  	struct thunderstrike *ts;
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1047  	int ret;
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1048
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1049  	ret = hid_parse(hdev);
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1050  	if (ret) {
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1051  		hid_err(hdev, "Parse failed\n");
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1052  		return ret;
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1053  	}
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1054
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1055  	switch (id->product) {
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1056  	case USB_DEVICE_ID_NVIDIA_THUNDERSTRIKE_CONTROLLER:
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1057  		shield_dev = thunderstrike_create(hdev);
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1058  		break;
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1059  	}
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1060
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1061  	if (unlikely(!shield_dev)) {
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1062  		hid_err(hdev, "Failed to identify SHIELD device\n");
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1063  		return -ENODEV;
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1064  	}
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1065  	if (IS_ERR(shield_dev)) {
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1066  		hid_err(hdev, "Failed to create SHIELD device\n");
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1067  		return PTR_ERR(shield_dev);
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1068  	}
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1069
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1070  	ts = container_of(shield_dev, struct thunderstrike, base);
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1071
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1072  	ret = hid_hw_start(hdev, HID_CONNECT_HIDINPUT);
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1073  	if (ret) {
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1074  		hid_err(hdev, "Failed to start HID device\n");
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1075  		goto err_haptics;
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1076  	}
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1077
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1078  	ret = hid_hw_open(hdev);
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1079  	if (ret) {
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1080  		hid_err(hdev, "Failed to open HID device\n");
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1081  		goto err_stop;
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1082  	}
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1083
> 3ab196f882377ed Rahul Rameshbabu   2023-08-07  1084  	thunderstrike_device_init_info(shield_dev);
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1085
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1086  	return ret;
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1087
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1088  err_stop:
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1089  	hid_hw_stop(hdev);
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1090  err_haptics:
> 2cc4637842495c6 Christophe JAILLET 2023-08-26  1091  	thunderstrike_destroy(hdev);
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1092  	return ret;
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1093  }
> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1094
>
kernel test robot Aug. 26, 2023, 9:43 p.m. UTC | #3
Hi Christophe,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linux-next/master]
[cannot apply to linus/master v6.5-rc7]
[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/Christophe-JAILLET/HID-nvidia-shield-Fix-a-missing-led_classdev_unregister-in-the-probe-error-handling-path/20230827-014602
base:   linux-next/master
patch link:    https://lore.kernel.org/r/4c9a8c7f6b4eb879dd7ef4d44bb6a80b3f126d25.1693070958.git.christophe.jaillet%40wanadoo.fr
patch subject: [PATCH 3/3] HID: nvidia-shield: Introduce thunderstrike_destroy()
config: i386-buildonly-randconfig-003-20230827 (https://download.01.org/0day-ci/archive/20230827/202308270516.Ch4MucBs-lkp@intel.com/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce: (https://download.01.org/0day-ci/archive/20230827/202308270516.Ch4MucBs-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202308270516.Ch4MucBs-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/hid/hid-nvidia-shield.c:1046:24: warning: variable 'ts' set but not used [-Wunused-but-set-variable]
           struct thunderstrike *ts;
                                 ^
   1 warning generated.


vim +/ts +1046 drivers/hid/hid-nvidia-shield.c

09308562d4afb1 Rahul Rameshbabu   2023-06-08  1042  
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1043  static int shield_probe(struct hid_device *hdev, const struct hid_device_id *id)
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1044  {
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1045  	struct shield_device *shield_dev = NULL;
09308562d4afb1 Rahul Rameshbabu   2023-06-08 @1046  	struct thunderstrike *ts;
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1047  	int ret;
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1048  
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1049  	ret = hid_parse(hdev);
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1050  	if (ret) {
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1051  		hid_err(hdev, "Parse failed\n");
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1052  		return ret;
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1053  	}
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1054  
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1055  	switch (id->product) {
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1056  	case USB_DEVICE_ID_NVIDIA_THUNDERSTRIKE_CONTROLLER:
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1057  		shield_dev = thunderstrike_create(hdev);
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1058  		break;
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1059  	}
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1060  
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1061  	if (unlikely(!shield_dev)) {
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1062  		hid_err(hdev, "Failed to identify SHIELD device\n");
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1063  		return -ENODEV;
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1064  	}
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1065  	if (IS_ERR(shield_dev)) {
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1066  		hid_err(hdev, "Failed to create SHIELD device\n");
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1067  		return PTR_ERR(shield_dev);
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1068  	}
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1069  
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1070  	ts = container_of(shield_dev, struct thunderstrike, base);
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1071  
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1072  	ret = hid_hw_start(hdev, HID_CONNECT_HIDINPUT);
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1073  	if (ret) {
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1074  		hid_err(hdev, "Failed to start HID device\n");
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1075  		goto err_haptics;
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1076  	}
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1077  
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1078  	ret = hid_hw_open(hdev);
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1079  	if (ret) {
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1080  		hid_err(hdev, "Failed to open HID device\n");
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1081  		goto err_stop;
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1082  	}
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1083  
3ab196f882377e Rahul Rameshbabu   2023-08-07  1084  	thunderstrike_device_init_info(shield_dev);
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1085  
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1086  	return ret;
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1087  
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1088  err_stop:
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1089  	hid_hw_stop(hdev);
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1090  err_haptics:
2cc4637842495c Christophe JAILLET 2023-08-26  1091  	thunderstrike_destroy(hdev);
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1092  	return ret;
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1093  }
09308562d4afb1 Rahul Rameshbabu   2023-06-08  1094
Rahul Rameshbabu Aug. 27, 2023, 7:41 p.m. UTC | #4
On Sat, 26 Aug, 2023 23:13:01 +0200 Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:
> Le 26/08/2023 à 22:00, kernel test robot a écrit :
>> Hi Christophe,
>> kernel test robot noticed the following build warnings:
>> [auto build test WARNING on linux-next/master]
>> [cannot apply to linus/master v6.5-rc7]
>> [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/Christophe-JAILLET/HID-nvidia-shield-Fix-a-missing-led_classdev_unregister-in-the-probe-error-handling-path/20230827-014602
>> base:   linux-next/master
>> patch link:    https://lore.kernel.org/r/4c9a8c7f6b4eb879dd7ef4d44bb6a80b3f126d25.1693070958.git.christophe.jaillet%40wanadoo.fr
>> patch subject: [PATCH 3/3] HID: nvidia-shield: Introduce thunderstrike_destroy()
>> config: parisc-allyesconfig (https://download.01.org/0day-ci/archive/20230827/202308270307.EDe7t62T-lkp@intel.com/config)
>> compiler: hppa-linux-gcc (GCC) 13.2.0
>
> On x86_64, gcc 12.3.0 does not complain. :(

The key to getting gcc to spew the warning is passing W=1 for the make
variable to get the compiler to invoke the unused warning.

  [nix-shell:~/Documents/linux]$ make help | grep -i W=
   make W=n   [targets] Enable extra build checks, n=1,2,3 where
 		Multiple levels can be combined with W=12 or W=123

  linux on  cjaillet/shield-fixup [?] via ❄️  impure (linux-6.1.31)
  ❯ make -C $dev/lib/modules/*/build M=$(pwd)/drivers/hid W=1 modules
    CC [M]  /home/binary-eater/Documents/linux/drivers/hid/hid-nvidia-shield.o
  /home/binary-eater/Documents/linux/drivers/hid/hid-nvidia-shield.c: In function ‘shield_probe’:
  /home/binary-eater/Documents/linux/drivers/hid/hid-nvidia-shield.c:1046:31: warning: variable ‘ts’ set but not used [-Wunused-but-set-variable]
   1046 |         struct thunderstrike *ts;
        |                               ^~
    MODPOST /home/binary-eater/Documents/linux/drivers/hid/Module.symvers
    CC [M]  /home/binary-eater/Documents/linux/drivers/hid/hid-nvidia-shield.mod.o
    LD [M]  /home/binary-eater/Documents/linux/drivers/hid/hid-nvidia-shield.ko
    BTF [M] /home/binary-eater/Documents/linux/drivers/hid/hid-nvidia-shield.ko

  linux on  cjaillet/shield-fixup [?] via ❄️  impure (linux-6.1.31) took 4s
  ❯ gcc --version
  gcc (GCC) 12.2.0
  Copyright (C) 2022 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Hope this is helpful.

-- Rahul Rameshbabu

>
> Let see first if there is some comment on the serie, then I'll send a v2 to fix
> the warning.
>
> CJ
>
>> reproduce: (https://download.01.org/0day-ci/archive/20230827/202308270307.EDe7t62T-lkp@intel.com/reproduce)
>> If you fix the issue in a separate patch/commit (i.e. not just a new version
>> of
>> the same patch/commit), kindly add following tags
>> | Reported-by: kernel test robot <lkp@intel.com>
>> | Closes: https://lore.kernel.org/oe-kbuild-all/202308270307.EDe7t62T-lkp@intel.com/
>> All warnings (new ones prefixed by >>):
>>     drivers/hid/hid-nvidia-shield.c: In function 'shield_probe':
>>>> drivers/hid/hid-nvidia-shield.c:1046:31: warning: variable 'ts' set but not used [-Wunused-but-set-variable]
>>      1046 |         struct thunderstrike *ts;
>>           |                               ^~
>> vim +/ts +1046 drivers/hid/hid-nvidia-shield.c
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1042
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1043  static int shield_probe(struct hid_device *hdev, const struct hid_device_id *id)
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1044  {
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1045  	struct shield_device *shield_dev = NULL;
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08 @1046  	struct thunderstrike *ts;
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1047  	int ret;
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1048
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1049  	ret = hid_parse(hdev);
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1050  	if (ret) {
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1051  		hid_err(hdev, "Parse failed\n");
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1052  		return ret;
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1053  	}
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1054
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1055  	switch (id->product) {
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1056  	case USB_DEVICE_ID_NVIDIA_THUNDERSTRIKE_CONTROLLER:
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1057  		shield_dev = thunderstrike_create(hdev);
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1058  		break;
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1059  	}
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1060
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1061  	if (unlikely(!shield_dev)) {
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1062  		hid_err(hdev, "Failed to identify SHIELD device\n");
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1063  		return -ENODEV;
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1064  	}
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1065  	if (IS_ERR(shield_dev)) {
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1066  		hid_err(hdev, "Failed to create SHIELD device\n");
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1067  		return PTR_ERR(shield_dev);
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1068  	}
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1069
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1070  	ts = container_of(shield_dev, struct thunderstrike, base);
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1071
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1072  	ret = hid_hw_start(hdev, HID_CONNECT_HIDINPUT);
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1073  	if (ret) {
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1074  		hid_err(hdev, "Failed to start HID device\n");
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1075  		goto err_haptics;
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1076  	}
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1077
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1078  	ret = hid_hw_open(hdev);
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1079  	if (ret) {
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1080  		hid_err(hdev, "Failed to open HID device\n");
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1081  		goto err_stop;
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1082  	}
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1083
>> 3ab196f882377ed Rahul Rameshbabu   2023-08-07  1084  	thunderstrike_device_init_info(shield_dev);
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1085
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1086  	return ret;
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1087
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1088  err_stop:
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1089  	hid_hw_stop(hdev);
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1090  err_haptics:
>> 2cc4637842495c6 Christophe JAILLET 2023-08-26  1091  	thunderstrike_destroy(hdev);
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1092  	return ret;
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1093  }
>> 09308562d4afb1a Rahul Rameshbabu   2023-06-08  1094
>>
diff mbox series

Patch

diff --git a/drivers/hid/hid-nvidia-shield.c b/drivers/hid/hid-nvidia-shield.c
index 849b3f8409a0..4e39e7c1a2c3 100644
--- a/drivers/hid/hid-nvidia-shield.c
+++ b/drivers/hid/hid-nvidia-shield.c
@@ -915,6 +915,20 @@  static struct shield_device *thunderstrike_create(struct hid_device *hdev)
 	return ERR_PTR(ret);
 }
 
+static void thunderstrike_destroy(struct hid_device *hdev)
+{
+	struct shield_device *dev = hid_get_drvdata(hdev);
+	struct thunderstrike *ts;
+
+	ts = container_of(dev, struct thunderstrike, base);
+
+	power_supply_unregister(ts->base.battery_dev.psy);
+	if (ts->haptics_dev)
+		input_unregister_device(ts->haptics_dev);
+	led_classdev_unregister(&ts->led_dev);
+	ida_free(&thunderstrike_ida, ts->id);
+}
+
 static int android_input_mapping(struct hid_device *hdev, struct hid_input *hi,
 				 struct hid_field *field,
 				 struct hid_usage *usage, unsigned long **bit,
@@ -1074,11 +1088,7 @@  static int shield_probe(struct hid_device *hdev, const struct hid_device_id *id)
 err_stop:
 	hid_hw_stop(hdev);
 err_haptics:
-	power_supply_unregister(ts->base.battery_dev.psy);
-	if (ts->haptics_dev)
-		input_unregister_device(ts->haptics_dev);
-	led_classdev_unregister(&ts->led_dev);
-	ida_free(&thunderstrike_ida, ts->id);
+	thunderstrike_destroy(hdev);
 	return ret;
 }
 
@@ -1090,11 +1100,7 @@  static void shield_remove(struct hid_device *hdev)
 	ts = container_of(dev, struct thunderstrike, base);
 
 	hid_hw_close(hdev);
-	power_supply_unregister(dev->battery_dev.psy);
-	if (ts->haptics_dev)
-		input_unregister_device(ts->haptics_dev);
-	led_classdev_unregister(&ts->led_dev);
-	ida_free(&thunderstrike_ida, ts->id);
+	thunderstrike_destroy(hdev);
 	del_timer_sync(&ts->psy_stats_timer);
 	cancel_work_sync(&ts->hostcmd_req_work);
 	hid_hw_stop(hdev);