From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Len Baker <len.baker@gmx.com>
Cc: Henrique de Moraes Holschuh <hmh@hmh.eng.br>,
Hans de Goede <hdegoede@redhat.com>,
Mark Gross <mgross@linux.intel.com>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Kees Cook <keescook@chromium.org>,
ibm-acpi-devel@lists.sourceforge.net,
platform-driver-x86@vger.kernel.org,
linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] platform/x86: thinkpad_acpi: Switch to common use of attributes
Date: Sun, 26 Sep 2021 13:32:16 +0200 [thread overview]
Message-ID: <YVBaQAFVX1CeQUPE@kroah.com> (raw)
In-Reply-To: <20210926111908.6950-1-len.baker@gmx.com>
On Sun, Sep 26, 2021 at 01:19:08PM +0200, Len Baker wrote:
> As noted in the "Deprecated Interfaces, Language Features, Attributes,
> and Conventions" documentation [1], size calculations (especially
> multiplication) should not be performed in memory allocator (or similar)
> function arguments due to the risk of them overflowing. This could lead
> to values wrapping around and a smaller allocation being made than the
> caller was expecting. Using those allocations could lead to linear
> overflows of heap memory and other misbehaviors.
>
> So, to avoid open-coded arithmetic in the kzalloc() call inside the
> create_attr_set() function the code must be refactored. Using the
> struct_size() helper is the fast solution but it is better to switch
> this code to common use of attributes.
>
> Then, remove all the custom code to manage hotkey attributes and use the
> attribute_group structure instead, refactoring the code accordingly.
> Also, to manage the optional hotkey attributes (hotkey_tablet_mode and
> hotkey_radio_sw) use the is_visible callback from the same structure.
>
> Moreover, now the hotkey_init_tablet_mode() function never returns a
> negative number. So, the check after the call can be safely removed.
>
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
>
> Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Len Baker <len.baker@gmx.com>
> ---
> Hi,
>
> Following the suggestions made by Greg I have switch the code to common
> use of attributes. However this code is untested. If someone could test
> it would be great.
Much better, thanks.
But, I have a few questions here:
> @@ -3161,9 +3106,7 @@ static void hotkey_exit(void)
> hotkey_poll_stop_sync();
> mutex_unlock(&hotkey_mutex);
> #endif
> -
> - if (hotkey_dev_attributes)
> - delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj);
> + sysfs_remove_group(&tpacpi_pdev->dev.kobj, &hotkey_attr_group);
Why do you have to manually add/remove these groups still?
A huge hint that something is going wrong is when you have to call a
sysfs_*() call from within a driver. There should be proper driver_*()
calls for you instead to get the job done.
As this is a platform device, why not set the dev_groups variable in the
platform_driver field so that these attribute groups get added and
removed automatically?
An example commit to look at that shows how this was converted for one
driver is 5bd08a4ae3d0 ("platform: x86: hp-wmi: convert platform driver
to use dev_groups"). See if that helps here as well.
thanks,
greg k-h
next prev parent reply other threads:[~2021-09-26 11:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-26 11:19 [PATCH v2] platform/x86: thinkpad_acpi: Switch to common use of attributes Len Baker
2021-09-26 11:32 ` Greg Kroah-Hartman [this message]
2021-09-26 11:49 ` Len Baker
2021-09-28 14:55 ` Hans de Goede
2021-09-28 16:04 ` Greg Kroah-Hartman
2021-09-28 17:37 ` Hans de Goede
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=YVBaQAFVX1CeQUPE@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=gustavoars@kernel.org \
--cc=hdegoede@redhat.com \
--cc=hmh@hmh.eng.br \
--cc=ibm-acpi-devel@lists.sourceforge.net \
--cc=keescook@chromium.org \
--cc=len.baker@gmx.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mgross@linux.intel.com \
--cc=platform-driver-x86@vger.kernel.org \
/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