From: Greg KH <greg@kroah.com>
To: Max Kellermann <max.kellermann@ionos.com>
Cc: Jean Delvare <jdelvare@suse.com>,
Guenter Roeck <linux@roeck-us.net>,
linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/7] drivers/hwmon: add local variable for newly allocated attribute_group**
Date: Mon, 9 Oct 2023 19:27:51 +0200 [thread overview]
Message-ID: <2023100908-pouring-synapse-75bd@gregkh> (raw)
In-Reply-To: <20231009165741.746184-2-max.kellermann@ionos.com>
On Mon, Oct 09, 2023 at 06:57:35PM +0200, Max Kellermann wrote:
> This allows the compiler to keep the pointer in a register and
Maybe, maybe not, there's no guarantee for register usage.
And it doesn't matter, this is a very slow path, no registers are
required :)
> prepares for making the struct field "const".
What struct field?
>
> Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
> ---
> drivers/hwmon/hwmon.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
> index c7dd3f5b2bd5..e50ab229b27d 100644
> --- a/drivers/hwmon/hwmon.c
> +++ b/drivers/hwmon/hwmon.c
> @@ -783,6 +783,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
> hdev = &hwdev->dev;
>
> if (chip) {
> + const struct attribute_group **new_groups;
> struct attribute **attrs;
> int ngroups = 2; /* terminating NULL plus &hwdev->groups */
>
> @@ -790,8 +791,8 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
> for (i = 0; groups[i]; i++)
> ngroups++;
>
> - hwdev->groups = kcalloc(ngroups, sizeof(*groups), GFP_KERNEL);
> - if (!hwdev->groups) {
> + hwdev->groups = new_groups = kcalloc(ngroups, sizeof(*new_groups), GFP_KERNEL);
So you have a const pointer AND a non-const pointer pointing to the same
thing?
> + if (!new_groups) {
> err = -ENOMEM;
> goto free_hwmon;
> }
> @@ -804,14 +805,14 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata,
>
> hwdev->group.attrs = attrs;
> ngroups = 0;
> - hwdev->groups[ngroups++] = &hwdev->group;
> + new_groups[ngroups++] = &hwdev->group;
This shoul be identical, you assign both above the same way, so why
change this?
>
> if (groups) {
> for (i = 0; groups[i]; i++)
> - hwdev->groups[ngroups++] = groups[i];
> + new_groups[ngroups++] = groups[i];
Same here.
thanks,
greg k-h
next prev parent reply other threads:[~2023-10-09 17:28 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-09 16:57 [PATCH 1/7] drivers/rtc/sysfs: move code to count_attribute_groups() Max Kellermann
2023-10-09 16:57 ` [PATCH 2/7] drivers/hwmon: add local variable for newly allocated attribute_group** Max Kellermann
2023-10-09 17:19 ` Guenter Roeck
2023-10-09 17:28 ` Max Kellermann
2023-10-09 19:36 ` Guenter Roeck
2023-10-09 17:27 ` Greg KH [this message]
2023-10-09 17:34 ` Max Kellermann
2023-10-09 16:57 ` [PATCH 3/7] drivers/extcon: " Max Kellermann
2023-10-09 17:28 ` Greg KH
2023-10-09 16:57 ` [PATCH 4/7] drivers/counter: " Max Kellermann
2023-10-09 17:28 ` Greg KH
2023-10-09 16:57 ` [PATCH 5/7] drivers/tty/serial_core: " Max Kellermann
2023-10-09 17:28 ` Greg Kroah-Hartman
2023-10-09 16:57 ` [PATCH 6/7] fs/sysfs/group: make attribute_group pointers const Max Kellermann
2023-10-09 17:24 ` Guenter Roeck
2023-10-09 20:05 ` Max Kellermann
2023-10-10 5:59 ` Greg Kroah-Hartman
2023-10-10 6:48 ` Joe Perches
2023-10-10 6:57 ` Greg Kroah-Hartman
2023-10-10 7:38 ` Max Kellermann
2023-10-10 8:01 ` Joe Perches
2023-10-09 17:25 ` Greg Kroah-Hartman
2023-10-09 17:30 ` Max Kellermann
2023-10-09 17:31 ` Greg Kroah-Hartman
2023-10-09 20:20 ` Max Kellermann
2023-10-09 16:57 ` [PATCH 7/7] block, drivers: make lots of attribute_group globals const Max Kellermann
2023-10-09 17:30 ` Greg Kroah-Hartman
2023-10-09 17:40 ` Max Kellermann
2023-10-09 17:24 ` [PATCH 1/7] drivers/rtc/sysfs: move code to count_attribute_groups() Greg KH
2023-10-09 18:01 ` Max Kellermann
2023-10-10 8:15 ` Alexandre Belloni
2023-10-10 8:24 ` Max Kellermann
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=2023100908-pouring-synapse-75bd@gregkh \
--to=greg@kroah.com \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=max.kellermann@ionos.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