mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: Guangshuo Li <lgs201920130244@gmail.com>,
	platform-driver-x86@vger.kernel.org
Cc: "Bao Cheng Su" <baocheng.su@siemens.com>,
	"Benedikt Niedermayr" <benedikt.niedermayr@siemens.com>,
	"Hans de Goede" <hansg@kernel.org>,
	"Henning Schild" <henning.schild@siemens.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Tobias Schaffner" <tobias.schaffner@siemens.com>,
	stable@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] platform/x86: simatic-ipc: fix platform device leak on registration failure
Date: Tue, 22 Sep 2026 11:07:25 +0200	[thread overview]
Message-ID: <9a96d707-ee9d-423c-86ad-2a1328b88fdf@web.de> (raw)
In-Reply-To: <CANUHTR9+rLuPrd1aifKws++POOKSm+2jxBaJaC1iF5z5x0e13Q@mail.gmail.com>

>> …
>>> +++ b/drivers/platform/x86/siemens/simatic-ipc.c
>> …
>>> @@ -118,8 +119,11 @@ static int register_platform_devices(u32 station_id)
>>>                       platform_device_register_data(NULL, pdevname,
>>>                               PLATFORM_DEVID_NONE, &platform_data,
>>>                               sizeof(struct simatic_ipc_platform));
>>> -             if (IS_ERR(ipc_batt_platform_device))
>>> -                     return PTR_ERR(ipc_batt_platform_device);
>>> +             if (IS_ERR(ipc_batt_platform_device)) {
>>> +                     ret = PTR_ERR(ipc_batt_platform_device);
>>> +                     ipc_batt_platform_device = NULL;
>>> +                     goto err_unregister;
>>> +             }
>> …
>>
>> How do you think about to avoid duplicate checks and variable resets
>> in such a function implementation?
> Would it make sense to share the cleanup path and rely on
> platform_device_unregister() handling NULL/ERR_PTR, like this?

It probably depends on corresponding case distinctions.


> +static void unregister_platform_devices(void)
> +{
> +        platform_device_unregister(ipc_wdt_platform_device);
> +        platform_device_unregister(ipc_led_platform_device);
> +        platform_device_unregister(ipc_batt_platform_device);
> +}

* Would you like to avoid the passing of any error pointers here?

* How do you think about the relevance for variable resets?


> +
>  static int register_platform_devices(u32 station_id)
>  {
>         return 0;
> +
> +err_unregister:
> +       unregister_platform_devices();
> +       return ret;
>  }…

Regards,
Markus

  reply	other threads:[~2026-09-22  9:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21  7:53 Guangshuo Li
2026-09-21 10:10 ` Markus Elfring
2026-09-22  8:13   ` Guangshuo Li
2026-09-22  9:07     ` Markus Elfring [this message]
2026-09-22  9:51     ` Dan Carpenter
2026-09-21 15:05 ` krzk
2026-09-22  2:38   ` Guangshuo Li
2026-09-21 15:09 ` krzk

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=9a96d707-ee9d-423c-86ad-2a1328b88fdf@web.de \
    --to=markus.elfring@web.de \
    --cc=baocheng.su@siemens.com \
    --cc=benedikt.niedermayr@siemens.com \
    --cc=hansg@kernel.org \
    --cc=henning.schild@siemens.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=lgs201920130244@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tobias.schaffner@siemens.com \
    /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®