From: Guenter Roeck <linux@roeck-us.net>
To: Lucas Magasweran <lucasrangit@gmail.com>
Cc: linux-hwmon@vger.kernel.org, jdelvare@suse.de
Subject: Re: hwmon_device_register_with_info registration API issue
Date: Fri, 4 May 2018 15:39:50 -0700 [thread overview]
Message-ID: <20180504223950.GA5392@roeck-us.net> (raw)
In-Reply-To: <1525472549.6877.81.camel@gmail.com>
On Sat, May 05, 2018 at 12:22:29AM +0200, Lucas Magasweran wrote:
> Hi Jean and al,
>
> Thank you for your Kernel Recipes 2016 talk about the new hwmon
> registration API [1].
>
> I'm trying to use the latest hwmon_device_register_with_info() API
> where hwmon core handles the sysfs attributes for me. However, I cannot
> use it with a NULL parent struct device *dev and non-NULL struct
> hwmon_chip_info *chip. My platform driver module_init() calls
> hwmon_device_register_with_info(). __hwmon_device_register() has a NULL
> pointer dereference error because it uses device managed memory
> allocation internally.
>
> For example,
>
> my_hwmon_dev = hwmon_device_register_with_info(NULL, "my_name", NULL,
> &my_hwmon_chip_info,
> NULL);
> --> __hwmon_device_register(NULL, "my_name", NULL,
> &my_hwmon_chip_info, NULL);
> ----> hwdev->groups = devm_kcalloc(NULL, ngroups,
> sizeof(*groups), GFP_KERNEL);
>
> I see that later in the function dev is checked for NULL in "hdev-
> >of_node = dev ? dev->of_node : NULL;" but it cannot be NULL for
> devm_kcalloc().
>
> I tried the following 4.10.17 patch because I expected the hwmon
> attributes to be stored with the hwmon device directly and not the
> struct device *dev parent. However, none of my attributes are showing
> up in /sys/class/hwmon#/.
>
I assume you mean /sys/class/hwmon/hwmon#/.
> Is my approach wrong?
>
Yes. Parent must not be NULL if chip is used. The use case of parent==NULL
and chip!=NULL is not and will not be supported. Also, the only reason
for supporting a NULL parent is that the thermal code uses it, and it
is all but impossible to change the thermal code to provide a device
pointer.
I would strongly suggest to modify your code and provide
a parent (a pointer to either a platform or hardware device).
Most likely that means to convert it to a platform device.
If you insist in not providing a parent, you'll have to use
hwmon_device_register_with_groups(). Of course, that means you'll
have to handle the attributes.
Guenter
next prev parent reply other threads:[~2018-05-04 22:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-04 22:22 hwmon_device_register_with_info registration API issue Lucas Magasweran
2018-05-04 22:39 ` Guenter Roeck [this message]
2018-05-08 11:43 ` [PATCH] hwmon: (core) check parent dev != NULL when chip != NULL Lucas Magasweran
2018-05-08 11:43 ` Lucas Magasweran
2018-05-08 22:16 ` Guenter Roeck
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=20180504223950.GA5392@roeck-us.net \
--to=linux@roeck-us.net \
--cc=jdelvare@suse.de \
--cc=linux-hwmon@vger.kernel.org \
--cc=lucasrangit@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.