diff mbox series

[3/3] macintosh/ams: Fix unused variable warning

Message ID 20240306125853.3714578-3-mpe@ellerman.id.au (mailing list archive)
State New
Headers show
Series [1/3] powerpc/64s: Fix get_hugepd_cache_index() build failure | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_ppctests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_selftests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.
snowpatch_ozlabs/github-powerpc_clang success Successfully ran 6 jobs.
snowpatch_ozlabs/github-powerpc_kernel_qemu success Successfully ran 23 jobs.

Commit Message

Michael Ellerman March 6, 2024, 12:58 p.m. UTC
If both CONFIG_SENSORS_AMS_PMU and CONFIG_SENSORS_AMS_I2C are unset,
there is an unused variable warning in the ams driver:

  drivers/macintosh/ams/ams-core.c: In function 'ams_init':
  drivers/macintosh/ams/ams-core.c:181:29: warning: unused variable 'np'
    181 |         struct device_node *np;

Fix it by using IS_ENABLED() to create a block for each case, and move
the variable declartion in there.

Probably the dependencies should be changed so that the driver can't be
built with both variants disabled, but that would be a larger change.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 drivers/macintosh/ams/ams-core.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

Comments

Christophe Leroy March 6, 2024, 1:17 p.m. UTC | #1
Le 06/03/2024 à 13:58, Michael Ellerman a écrit :
> If both CONFIG_SENSORS_AMS_PMU and CONFIG_SENSORS_AMS_I2C are unset,
> there is an unused variable warning in the ams driver:
> 
>    drivers/macintosh/ams/ams-core.c: In function 'ams_init':
>    drivers/macintosh/ams/ams-core.c:181:29: warning: unused variable 'np'
>      181 |         struct device_node *np;
> 
> Fix it by using IS_ENABLED() to create a block for each case, and move
> the variable declartion in there.
> 
> Probably the dependencies should be changed so that the driver can't be
> built with both variants disabled, but that would be a larger change.

Can be done easily that way I think:

diff --git a/drivers/macintosh/Kconfig b/drivers/macintosh/Kconfig
index a0e717a986dc..fb38f684444f 100644
--- a/drivers/macintosh/Kconfig
+++ b/drivers/macintosh/Kconfig
@@ -262,7 +262,7 @@ config SENSORS_AMS
  	  will be called ams.

  config SENSORS_AMS_PMU
-	bool "PMU variant"
+	bool "PMU variant" if SENSORS_AMS_I2C
  	depends on SENSORS_AMS && ADB_PMU
  	default y
  	help


> 
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
>   drivers/macintosh/ams/ams-core.c | 29 ++++++++++++++---------------
>   1 file changed, 14 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/macintosh/ams/ams-core.c b/drivers/macintosh/ams/ams-core.c
> index c978b4272daa..22d3e6605287 100644
> --- a/drivers/macintosh/ams/ams-core.c
> +++ b/drivers/macintosh/ams/ams-core.c
> @@ -178,25 +178,24 @@ int ams_sensor_attach(void)
>   
>   static int __init ams_init(void)
>   {
> -	struct device_node *np;
> -
>   	spin_lock_init(&ams_info.irq_lock);
>   	mutex_init(&ams_info.lock);
>   	INIT_WORK(&ams_info.worker, ams_worker);
>   
> -#ifdef CONFIG_SENSORS_AMS_I2C
> -	np = of_find_node_by_name(NULL, "accelerometer");
> -	if (np && of_device_is_compatible(np, "AAPL,accelerometer_1"))
> -		/* Found I2C motion sensor */
> -		return ams_i2c_init(np);
> -#endif
> -
> -#ifdef CONFIG_SENSORS_AMS_PMU
> -	np = of_find_node_by_name(NULL, "sms");
> -	if (np && of_device_is_compatible(np, "sms"))
> -		/* Found PMU motion sensor */
> -		return ams_pmu_init(np);
> -#endif
> +	if (IS_ENABLED(CONFIG_SENSORS_AMS_I2C)) {
> +		struct device_node *np = of_find_node_by_name(NULL, "accelerometer");
> +		if (np && of_device_is_compatible(np, "AAPL,accelerometer_1"))
> +			/* Found I2C motion sensor */
> +			return ams_i2c_init(np);
> +	}
> +
> +	if (IS_ENABLED(CONFIG_SENSORS_AMS_PMU)) {
> +		struct device_node *np = of_find_node_by_name(NULL, "sms");
> +		if (np && of_device_is_compatible(np, "sms"))
> +			/* Found PMU motion sensor */
> +			return ams_pmu_init(np);
> +	}
> +
>   	return -ENODEV;
>   }
>
Michael Ellerman March 7, 2024, 5:32 a.m. UTC | #2
Christophe Leroy <christophe.leroy@csgroup.eu> writes:
> Le 06/03/2024 à 13:58, Michael Ellerman a écrit :
>> If both CONFIG_SENSORS_AMS_PMU and CONFIG_SENSORS_AMS_I2C are unset,
>> there is an unused variable warning in the ams driver:
>> 
>>    drivers/macintosh/ams/ams-core.c: In function 'ams_init':
>>    drivers/macintosh/ams/ams-core.c:181:29: warning: unused variable 'np'
>>      181 |         struct device_node *np;
>> 
>> Fix it by using IS_ENABLED() to create a block for each case, and move
>> the variable declartion in there.
>> 
>> Probably the dependencies should be changed so that the driver can't be
>> built with both variants disabled, but that would be a larger change.
>
> Can be done easily that way I think:
>
> diff --git a/drivers/macintosh/Kconfig b/drivers/macintosh/Kconfig
> index a0e717a986dc..fb38f684444f 100644
> --- a/drivers/macintosh/Kconfig
> +++ b/drivers/macintosh/Kconfig
> @@ -262,7 +262,7 @@ config SENSORS_AMS
>   	  will be called ams.
>
>   config SENSORS_AMS_PMU
> -	bool "PMU variant"
> +	bool "PMU variant" if SENSORS_AMS_I2C
>   	depends on SENSORS_AMS && ADB_PMU
>   	default y
>   	help

Thanks. It's a little clunky. For example if you answer no to both
prompts, it still selects SENSORS_AMS_PMU, but I guess it doesn't really
matter.

  $ make oldconfig
  ...
    Apple Motion Sensor driver (SENSORS_AMS) [N/m/y/?] (NEW) y
      PMU variant (SENSORS_AMS_PMU) [Y/n/?] (NEW) n
      I2C variant (SENSORS_AMS_I2C) [Y/n/?] (NEW) n
  #
  # configuration written to .config
  #
  make[1]: Leaving directory '/home/michael/linux/.build'
  
  $ grep SENSORS_AMS .build/.config
  CONFIG_SENSORS_AMS=y
  CONFIG_SENSORS_AMS_PMU=y
  # CONFIG_SENSORS_AMS_I2C is not set


I'll turn to this into a patch and add your SoB?

cheers
Christophe Leroy March 7, 2024, 6:29 a.m. UTC | #3
Le 07/03/2024 à 06:32, Michael Ellerman a écrit :
> Christophe Leroy <christophe.leroy@csgroup.eu> writes:
>> Le 06/03/2024 à 13:58, Michael Ellerman a écrit :
>>> If both CONFIG_SENSORS_AMS_PMU and CONFIG_SENSORS_AMS_I2C are unset,
>>> there is an unused variable warning in the ams driver:
>>>
>>>     drivers/macintosh/ams/ams-core.c: In function 'ams_init':
>>>     drivers/macintosh/ams/ams-core.c:181:29: warning: unused variable 'np'
>>>       181 |         struct device_node *np;
>>>
>>> Fix it by using IS_ENABLED() to create a block for each case, and move
>>> the variable declartion in there.
>>>
>>> Probably the dependencies should be changed so that the driver can't be
>>> built with both variants disabled, but that would be a larger change.
>>
>> Can be done easily that way I think:
>>
>> diff --git a/drivers/macintosh/Kconfig b/drivers/macintosh/Kconfig
>> index a0e717a986dc..fb38f684444f 100644
>> --- a/drivers/macintosh/Kconfig
>> +++ b/drivers/macintosh/Kconfig
>> @@ -262,7 +262,7 @@ config SENSORS_AMS
>>    	  will be called ams.
>>
>>    config SENSORS_AMS_PMU
>> -	bool "PMU variant"
>> +	bool "PMU variant" if SENSORS_AMS_I2C
>>    	depends on SENSORS_AMS && ADB_PMU
>>    	default y
>>    	help
> 
> Thanks. It's a little clunky. For example if you answer no to both
> prompts, it still selects SENSORS_AMS_PMU, but I guess it doesn't really
> matter.
> 
>    $ make oldconfig
>    ...
>      Apple Motion Sensor driver (SENSORS_AMS) [N/m/y/?] (NEW) y
>        PMU variant (SENSORS_AMS_PMU) [Y/n/?] (NEW) n
>        I2C variant (SENSORS_AMS_I2C) [Y/n/?] (NEW) n
>    #
>    # configuration written to .config
>    #
>    make[1]: Leaving directory '/home/michael/linux/.build'
>    
>    $ grep SENSORS_AMS .build/.config
>    CONFIG_SENSORS_AMS=y
>    CONFIG_SENSORS_AMS_PMU=y
>    # CONFIG_SENSORS_AMS_I2C is not set
> 
> 
> I'll turn to this into a patch and add your SoB?

That's fine for me.

You can alternatively use Suggested-by: , I don't really mind.

Thanks
Christophe
diff mbox series

Patch

diff --git a/drivers/macintosh/ams/ams-core.c b/drivers/macintosh/ams/ams-core.c
index c978b4272daa..22d3e6605287 100644
--- a/drivers/macintosh/ams/ams-core.c
+++ b/drivers/macintosh/ams/ams-core.c
@@ -178,25 +178,24 @@  int ams_sensor_attach(void)
 
 static int __init ams_init(void)
 {
-	struct device_node *np;
-
 	spin_lock_init(&ams_info.irq_lock);
 	mutex_init(&ams_info.lock);
 	INIT_WORK(&ams_info.worker, ams_worker);
 
-#ifdef CONFIG_SENSORS_AMS_I2C
-	np = of_find_node_by_name(NULL, "accelerometer");
-	if (np && of_device_is_compatible(np, "AAPL,accelerometer_1"))
-		/* Found I2C motion sensor */
-		return ams_i2c_init(np);
-#endif
-
-#ifdef CONFIG_SENSORS_AMS_PMU
-	np = of_find_node_by_name(NULL, "sms");
-	if (np && of_device_is_compatible(np, "sms"))
-		/* Found PMU motion sensor */
-		return ams_pmu_init(np);
-#endif
+	if (IS_ENABLED(CONFIG_SENSORS_AMS_I2C)) {
+		struct device_node *np = of_find_node_by_name(NULL, "accelerometer");
+		if (np && of_device_is_compatible(np, "AAPL,accelerometer_1"))
+			/* Found I2C motion sensor */
+			return ams_i2c_init(np);
+	}
+
+	if (IS_ENABLED(CONFIG_SENSORS_AMS_PMU)) {
+		struct device_node *np = of_find_node_by_name(NULL, "sms");
+		if (np && of_device_is_compatible(np, "sms"))
+			/* Found PMU motion sensor */
+			return ams_pmu_init(np);
+	}
+
 	return -ENODEV;
 }