mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans de Goede <hansg@kernel.org>
To: "Wentao Liang" <vulab@iscas.ac.cn>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] platform/x86: x86-android-tablets: fix codec teardown if poweroff handler setup fails
Date: Tue, 3 Nov 2026 17:28:11 +0100	[thread overview]
Message-ID: <5babb98b-7d6e-4f3a-b306-b40b30c4cdfa@kernel.org> (raw)
In-Reply-To: <20261103105544.1394559-1-vulab@iscas.ac.cn>

Hi,

On 3-Nov-26 11:55 AM, Wentao Liang wrote:
> lenovo_yoga_tab2_830_1050_init_codec() stores the codec device reference,
> the pinctrl handle and the pin mappings in globals on success; they are
> only released by lenovo_yoga_tab2_830_1050_exit(). If the
> register_sys_off_handler() call which follows it fails, the init callback
> returns an error before the exit callback has been registered with the
> framework, so the codec device reference and the other resources are
> never released.
> 
> Factor the codec teardown out into a helper and call it from the error
> path of both init callbacks.
> 
> Fixes: 4ce8f4c2027d ("platform/x86: x86-android-tablets: Fix Lenovo Yoga Tablet 2 830/1050 poweroff again")
> Cc: stable@vger.kernel.org
> Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>  .../platform/x86/x86-android-tablets/lenovo.c | 27 +++++++++++++------
>  1 file changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/platform/x86/x86-android-tablets/lenovo.c b/drivers/platform/x86/x86-android-tablets/lenovo.c
> index 52d96ae89078..294986f84ce8 100644
> --- a/drivers/platform/x86/x86-android-tablets/lenovo.c
> +++ b/drivers/platform/x86/x86-android-tablets/lenovo.c
> @@ -548,6 +548,14 @@ static int __init lenovo_yoga_tab2_830_1050_init_codec(void)
>  	return ret;
>  }
>  
> +static void lenovo_yoga_tab2_830_1050_exit_codec(void)
> +{
> +	device_remove_software_node(lenovo_yoga_tab2_830_1050_codec_dev);
> +	pinctrl_put(lenovo_yoga_tab2_830_1050_codec_pinctrl);
> +	pinctrl_unregister_mappings(&lenovo_yoga_tab2_830_1050_codec_pinctrl_map);
> +	put_device(lenovo_yoga_tab2_830_1050_codec_dev);
> +}
> +
>  /*
>   * These tablet's DSDT does not set acpi_gbl_reduced_hardware, so acpi_power_off()
>   * gets used as pm_power_off handler. This causes "poweroff" on these tablets
> @@ -578,8 +586,11 @@ static int __init lenovo_yoga_tab2_830_1050_init(struct device *dev)
>  	lenovo_yoga_tab2_830_1050_sys_off_handler =
>  		register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_FIRMWARE + 1,
>  					 lenovo_yoga_tab2_830_1050_power_off, NULL);
> -	if (IS_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler))
> -		return PTR_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler);
> +	if (IS_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler)) {
> +		ret = PTR_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler);
> +		lenovo_yoga_tab2_830_1050_exit_codec();
> +		return ret;
> +	}

lenovo_yoga_tab2_830_1050_exit_codec() does not touch lenovo_yoga_tab2_830_1050_sys_off_handler,
so there is no reason to store the error-code in ret before calling it.

Please just keep this line:

		return PTR_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler);

as-is.


>  
>  	return 0;
>  }
> @@ -588,10 +599,7 @@ static void lenovo_yoga_tab2_830_1050_exit(void)
>  {
>  	unregister_sys_off_handler(lenovo_yoga_tab2_830_1050_sys_off_handler);
>  
> -	device_remove_software_node(lenovo_yoga_tab2_830_1050_codec_dev);
> -	pinctrl_put(lenovo_yoga_tab2_830_1050_codec_pinctrl);
> -	pinctrl_unregister_mappings(&lenovo_yoga_tab2_830_1050_codec_pinctrl_map);
> -	put_device(lenovo_yoga_tab2_830_1050_codec_dev);
> +	lenovo_yoga_tab2_830_1050_exit_codec();

Please also remove the empty line which was there to group all the codec
cleanup calls together which now no longer is necessary.

>  }
>  
>  /*
> @@ -776,8 +784,11 @@ static int __init lenovo_yoga_tab2_1380_init(struct device *dev)
>  	lenovo_yoga_tab2_830_1050_sys_off_handler =
>  		register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_FIRMWARE + 1,
>  					 lenovo_yoga_tab2_830_1050_power_off, NULL);
> -	if (IS_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler))
> -		return PTR_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler);
> +	if (IS_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler)) {
> +		ret = PTR_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler);
> +		lenovo_yoga_tab2_830_1050_exit_codec();
> +		return ret;
> +	}

Same as above, please keep this line:

		return PTR_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler);

as-is.

Regards,

Hans


      parent reply	other threads:[~2026-11-03 16:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 10:55 Wentao Liang
2026-11-03 11:10 ` Krzysztof Kozlowski
2026-11-03 16:28 ` Hans de Goede [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5babb98b-7d6e-4f3a-b306-b40b30c4cdfa@kernel.org \
    --to=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=vulab@iscas.ac.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®