From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Rosen Penev <rosenp@gmail.com>
Cc: Stuart Hayes <stuart.w.hayes@gmail.com>,
Hans de Goede <hansg@kernel.org>,
Doug Warzecha <Douglas_Warzecha@dell.com>,
Andrew Morton <akpm@osdl.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
platform-driver-x86@vger.kernel.org
Subject: Re: [PATCH v3 3/4] platform/x86: dell: dcdbas: Release the SMI buffer in remove
Date: Fri, 20 Nov 2026 11:37:31 +0200 (EET) [thread overview]
Message-ID: <db9e6534-ed2b-4abb-6d4a-906fc7ad18dc@linux.intel.com> (raw)
In-Reply-To: <20261118035638.11773-4-rosenp@gmail.com>
On Tue, 17 Nov 2026, Rosen Penev wrote:
> dcdbas_exit() frees the SMI data buffer before
> platform_device_unregister() removes the sysfs attributes, and without
This is very confusingly written, platform_device_unregister() does not
remove sysfs attributes. dcdbas_remove() does as is written below.
I think the entire sysfs attribute discussion (which is also stating
contradicting things) is sidetracking what looks to be the main problem,
that something is done in dcdbas_exit() that should be done in
dcdbas_remove(), I needed to read very much between the lines and had
already misunderstood what the all-over-the-place changelog had spewn on
my face.
Also, why isn't this driver using .dev_groups??
> holding smi_data_lock.
Not sure why this is relevant, this looks an ordering problem, not a
locking problem??
It's further reinforced by the fact that you did not make smi_data_lock
related changes in the patch, AFAICT.
> The comment claims that only at module exit can
> all sysfs attributes be released, but device attributes do not pin the
> module: while rmmod runs, smi_data_write() or smi_data_buf_size_store()
> can still be executing. They can then memcpy() into the buffer as it is
> freed, or allocate a new buffer that is never freed.
>
> sysfs_remove_group() in dcdbas_remove() waits for running attribute
> handlers, and dcdbas_pdev is still valid at that point. Free the buffer
> there, or unmap the firmware-provided buffer when WSMT is in use, and
> also do it when probe fails after dcdbas_check_wsmt() mapped the
> firmware buffer. Reset the WSMT state with it so a later probe starts
> clean.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> drivers/platform/x86/dell/dcdbas.c | 44 ++++++++++++++++++------------
> 1 file changed, 26 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/platform/x86/dell/dcdbas.c b/drivers/platform/x86/dell/dcdbas.c
> index 6bab3e0619bc..1f64f707744c 100644
> --- a/drivers/platform/x86/dell/dcdbas.c
> +++ b/drivers/platform/x86/dell/dcdbas.c
> @@ -97,6 +97,20 @@ static void smi_data_buf_free(void)
> dcdbas_smi_free(&smi_buf);
> }
>
> +/* Free the SMI data buffer, or unmap the firmware one when WSMT is in use */
> +static void dcdbas_release_buffer(void)
> +{
> + if (wsmt_enabled) {
> + memunmap(bios_buffer);
> + bios_buffer = NULL;
> + smi_buf = (struct smi_buffer){};
> + max_smi_data_buf_size = MAX_SMI_DATA_BUF_SIZE;
> + wsmt_enabled = false;
> + } else {
> + smi_data_buf_free();
> + }
> +}
> +
> /**
> * smi_data_buf_realloc: grow SMI data buffer if needed
> */
> @@ -683,11 +697,11 @@ static int dcdbas_probe(struct platform_device *dev)
> */
> error = dma_set_coherent_mask(&dcdbas_pdev->dev, DMA_BIT_MASK(32));
> if (error)
> - return error;
> + goto err_release_buffer;
>
> error = sysfs_create_group(&dev->dev.kobj, &dcdbas_attr_group);
> if (error)
> - return error;
> + goto err_release_buffer;
>
> register_reboot_notifier(&dcdbas_reboot_nb);
>
> @@ -695,12 +709,22 @@ static int dcdbas_probe(struct platform_device *dev)
> DRIVER_DESCRIPTION, DRIVER_VERSION);
>
> return 0;
> +
> +err_release_buffer:
> + dcdbas_release_buffer();
> + return error;
> }
>
> static void dcdbas_remove(struct platform_device *dev)
> {
> unregister_reboot_notifier(&dcdbas_reboot_nb);
> sysfs_remove_group(&dev->dev.kobj, &dcdbas_attr_group);
> +
> + /*
> + * sysfs_remove_group() waited for any attribute handler still
> + * running, so nothing else uses the buffer now.
> + */
> + dcdbas_release_buffer();
> }
>
> static struct platform_driver dcdbas_driver = {
> @@ -749,22 +773,6 @@ static int __init dcdbas_init(void)
> */
> static void __exit dcdbas_exit(void)
> {
> - /*
> - * make sure functions that use dcdbas_pdev are called
> - * before platform_device_unregister
> - */
> - unregister_reboot_notifier(&dcdbas_reboot_nb);
> -
> - /*
> - * We have to free the buffer here instead of dcdbas_remove
> - * because only in module exit function we can be sure that
> - * all sysfs attributes belonging to this module have been
> - * released.
> - */
> - if (dcdbas_pdev)
> - smi_data_buf_free();
> - if (bios_buffer)
> - memunmap(bios_buffer);
> platform_device_unregister(dcdbas_pdev_reg);
> platform_driver_unregister(&dcdbas_driver);
> }
>
--
i.
next prev parent reply other threads:[~2026-11-20 9:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 3:56 [PATCH v3 0/4] platform/x86: dell: dcdbas: Fix SMI completion wait and buffer handling Rosen Penev
2026-11-18 3:56 ` [PATCH v3 1/4] platform/x86: dell: dcdbas: Actually wait for the host control SMI Rosen Penev
2026-11-19 20:34 ` Andy Shevchenko
2026-11-18 3:56 ` [PATCH v3 2/4] platform/x86: dell: dcdbas: Suppress bind attributes of the platform driver Rosen Penev
2026-11-19 20:34 ` Andy Shevchenko
2026-11-18 3:56 ` [PATCH v3 3/4] platform/x86: dell: dcdbas: Release the SMI buffer in remove Rosen Penev
2026-11-20 9:37 ` Ilpo Järvinen [this message]
2026-11-18 3:56 ` [PATCH v3 4/4] platform/x86: dell: dcdbas: Validate the WSMT buffer description Rosen Penev
2026-11-19 20:39 ` Andy Shevchenko
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=db9e6534-ed2b-4abb-6d4a-906fc7ad18dc@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=Douglas_Warzecha@dell.com \
--cc=akpm@osdl.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=hansg@kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=rosenp@gmail.com \
--cc=stuart.w.hayes@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.