[PATCH] platform/x86: thinkpad-acpi: Add error handling for tpacpi_check_quirks

Wentao Liang posted 1 patch 10 months, 1 week ago
drivers/platform/x86/thinkpad_acpi.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH] platform/x86: thinkpad-acpi: Add error handling for tpacpi_check_quirks
Posted by Wentao Liang 10 months, 1 week ago
In tpacpi_battery_init(), the return value of tpacpi_check_quirks() needs
to be checked. The battery should not be hooked if there is no matched
battery information in quirk table.

Add an error check and return -ENODEV immediately if the device fail
the check.

Fixes: 1a32ebb26ba9 ("platform/x86: thinkpad_acpi: Support battery quirk")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/platform/x86/thinkpad_acpi.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 2cfb2ac3f465..a3227f60aa43 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -9969,11 +9969,15 @@ static const struct tpacpi_quirk battery_quirk_table[] __initconst = {
 
 static int __init tpacpi_battery_init(struct ibm_init_struct *ibm)
 {
+	unsigned long r;
+
 	memset(&battery_info, 0, sizeof(battery_info));
 
-	tp_features.battery_force_primary = tpacpi_check_quirks(
+	r = tp_features.battery_force_primary = tpacpi_check_quirks(
 					battery_quirk_table,
 					ARRAY_SIZE(battery_quirk_table));
+	if (!r)
+		return -ENODEV;
 
 	battery_hook_register(&battery_hook);
 	return 0;
-- 
2.42.0.windows.2
Re: [PATCH] platform/x86: thinkpad-acpi: Add error handling for tpacpi_check_quirks
Posted by Ilpo Järvinen 10 months ago
On Wed, 2 Apr 2025, Wentao Liang wrote:

> In tpacpi_battery_init(), the return value of tpacpi_check_quirks() needs
> to be checked. The battery should not be hooked if there is no matched
> battery information in quirk table.
> 
> Add an error check and return -ENODEV immediately if the device fail
> the check.
> 
> Fixes: 1a32ebb26ba9 ("platform/x86: thinkpad_acpi: Support battery quirk")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>  drivers/platform/x86/thinkpad_acpi.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
> index 2cfb2ac3f465..a3227f60aa43 100644
> --- a/drivers/platform/x86/thinkpad_acpi.c
> +++ b/drivers/platform/x86/thinkpad_acpi.c
> @@ -9969,11 +9969,15 @@ static const struct tpacpi_quirk battery_quirk_table[] __initconst = {
>  
>  static int __init tpacpi_battery_init(struct ibm_init_struct *ibm)
>  {
> +	unsigned long r;
> +
>  	memset(&battery_info, 0, sizeof(battery_info));
>  
> -	tp_features.battery_force_primary = tpacpi_check_quirks(
> +	r = tp_features.battery_force_primary = tpacpi_check_quirks(

Please don't do a double assignment. You can assign r to 
tp_features.battery_force_primary after the if check.

>  					battery_quirk_table,
>  					ARRAY_SIZE(battery_quirk_table));
> +	if (!r)
> +		return -ENODEV;
>  
>  	battery_hook_register(&battery_hook);
>  	return 0;
> 

-- 
 i.