From: Raul E Rangel <rrangel@chromium.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Alan Stern <stern@rowland.harvard.edu>,
Guenter Roeck <groeck@google.com>,
linux-usb@vger.kernel.org, Guenter Roeck <groeck@chromium.org>,
Oliver Neukum <oneukum@suse.com>,
Daniel Kurtz <djkurtz@chromium.org>,
zwisler@chromium.org,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
Dmitry Torokhov <dtor@chromium.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
"Gustavo A. R. Silva" <gustavo@embeddedor.com>,
Miquel Raynal <miquel.raynal@bootlin.com>,
Johan Hovold <johan@kernel.org>,
Mathias Nyman <mathias.nyman@linux.intel.com>,
Raul Rangel <rrangel@chromium.org>
Subject: [v3] usb/hcd: Send a uevent signaling that the host controller had died
Date: Thu, 18 Apr 2019 09:29:02 -0600 [thread overview]
Message-ID: <20190418152902.GA185502@google.com> (raw)
On Thu, Apr 18, 2019 at 04:30:48PM +0200, Greg Kroah-Hartman wrote:
> On Thu, Apr 18, 2019 at 10:21:32AM -0400, Alan Stern wrote:
> > On Thu, 18 Apr 2019, Greg Kroah-Hartman wrote:
> >
> > > On Wed, Apr 17, 2019 at 04:20:09PM -0700, Guenter Roeck wrote:
> > > > On Wed, Apr 17, 2019 at 3:41 PM Raul Rangel <rrangel@chromium.org> wrote:
> > > > >
> > > > > On Wed, Apr 17, 2019 at 03:23:52PM -0700, Guenter Roeck wrote:
> > > > > > On Wed, Apr 17, 2019 at 3:11 PM Raul Rangel <rrangel@chromium.org> wrote:
> > > > > > >
> > > > > > > On Wed, Apr 17, 2019 at 04:39:23PM -0400, Alan Stern wrote:
> > > > > > > >
> > > > > > > > This sounds like a golden opportunity! Submit a separate patch making
> > > > > > > > the parameter to kobject_uevent_env be const (actually const char *
> > > > > > > > const []), then submit this patch on top of that one.
> > > > > > > So there are other parts of the code base that dynamically create their
> > > > > > > array values. So by making the function take const, it breaks :(
> > > > > >
> > > > > > Confused. The calling code can still be non-const. I don't see the
> > > > > > parameter modified in kobject_uevent_env(), so declaring it const
> > > > > > should be possible. Can you give an example of code that no longer
> > > > > > works ?
> > > > > static int notify_user_space(struct thermal_zone_device *tz, int trip)
> > > > > {
> > > > > char *thermal_prop[5];
> > > > > int i;
> > > > >
> > > > > mutex_lock(&tz->lock);
> > > > > thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", tz->type);
> > > > > thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", tz->temperature);
> > > > > thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d", trip);
> > > > > thermal_prop[3] = kasprintf(GFP_KERNEL, "EVENT=%d", tz->notify_event);
> > > > > thermal_prop[4] = NULL;
> > > > > kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop);
> > > > > for (i = 0; i < 4; ++i)
> > > > > kfree(thermal_prop[i]);
> > > > > mutex_unlock(&tz->lock);
> > > > > return 0;
> > > > > }
> > > > >
> > > > > drivers/thermal/user_space.c:48:52: error: passing 'char *[5]' to parameter of type 'const char *const *' discards qualifiers in nested pointer types [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> > > > > kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop);
> > > > > ^~~~~~~~~~~~
> > > > > include/linux/kobject.h:238:22: note: passing argument to parameter 'envp' here
> > > > > const char *const envp[]);
> > > > > ^
> > > > >
> > > > > http://c-faq.com/ansi/constmismatch.html explains why it fails.
> > > > >
> > > > Interesting. One never stops learning. So the best you could do would
> > > > be char * const envp[], but I guess that doesn't help much.
> > >
> > > Yeah, I went down this path a year or so ago and had to give it up as
> > > well :(
> >
> > Well, the signature could still be changed as Guenter suggests.
> >
> > And the array being added in the new code could still be static.
> > After all, there isn't really any danger that the contents of those
> > strings will be modified, right? It's just that the const modifiers
> > weren't put in until it was too late and there were too many existing
> > callers. Perhaps a comment about this could be included in the
> > kerneldoc for kobject_uevent_env.
>
> I am all for changing this, but I remember I tried to, and somehow
> failed, but I don't remember the full details sorry, it was a while ago.
> If someone figures out how to make this all const, I will gladly take
> that patch.
>
Well we could use varargs...
int kobject_uevent_env(struct kobject *kobj,
enum kobject_action action,
...);
This will accept both const char* and char *.
Example https://repl.it/@RaulRangel/Const-char-var-args
It seems like most callers have a fixed number of env params, so you
wouldn't need a function that takes a list.
> thanks,
>
> greg k-h
WARNING: multiple messages have this Message-ID (diff)
From: Raul Rangel <rrangel@chromium.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Alan Stern <stern@rowland.harvard.edu>,
Guenter Roeck <groeck@google.com>,
linux-usb@vger.kernel.org, Guenter Roeck <groeck@chromium.org>,
Oliver Neukum <oneukum@suse.com>,
Daniel Kurtz <djkurtz@chromium.org>,
zwisler@chromium.org,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
Dmitry Torokhov <dtor@chromium.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
"Gustavo A. R. Silva" <gustavo@embeddedor.com>,
Miquel Raynal <miquel.raynal@bootlin.com>,
Johan Hovold <johan@kernel.org>,
Mathias Nyman <mathias.nyman@linux.intel.com>,
Raul Rangel <rrangel@chromium.org>
Subject: Re: [PATCH v3] usb/hcd: Send a uevent signaling that the host controller had died
Date: Thu, 18 Apr 2019 09:29:02 -0600 [thread overview]
Message-ID: <20190418152902.GA185502@google.com> (raw)
Message-ID: <20190418152902.EbOs-z9PHLmkqnsLhi8BmX-QP3WVheE3d4mScAAwqrw@z> (raw)
In-Reply-To: <20190418143048.GA11555@kroah.com>
On Thu, Apr 18, 2019 at 04:30:48PM +0200, Greg Kroah-Hartman wrote:
> On Thu, Apr 18, 2019 at 10:21:32AM -0400, Alan Stern wrote:
> > On Thu, 18 Apr 2019, Greg Kroah-Hartman wrote:
> >
> > > On Wed, Apr 17, 2019 at 04:20:09PM -0700, Guenter Roeck wrote:
> > > > On Wed, Apr 17, 2019 at 3:41 PM Raul Rangel <rrangel@chromium.org> wrote:
> > > > >
> > > > > On Wed, Apr 17, 2019 at 03:23:52PM -0700, Guenter Roeck wrote:
> > > > > > On Wed, Apr 17, 2019 at 3:11 PM Raul Rangel <rrangel@chromium.org> wrote:
> > > > > > >
> > > > > > > On Wed, Apr 17, 2019 at 04:39:23PM -0400, Alan Stern wrote:
> > > > > > > >
> > > > > > > > This sounds like a golden opportunity! Submit a separate patch making
> > > > > > > > the parameter to kobject_uevent_env be const (actually const char *
> > > > > > > > const []), then submit this patch on top of that one.
> > > > > > > So there are other parts of the code base that dynamically create their
> > > > > > > array values. So by making the function take const, it breaks :(
> > > > > >
> > > > > > Confused. The calling code can still be non-const. I don't see the
> > > > > > parameter modified in kobject_uevent_env(), so declaring it const
> > > > > > should be possible. Can you give an example of code that no longer
> > > > > > works ?
> > > > > static int notify_user_space(struct thermal_zone_device *tz, int trip)
> > > > > {
> > > > > char *thermal_prop[5];
> > > > > int i;
> > > > >
> > > > > mutex_lock(&tz->lock);
> > > > > thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", tz->type);
> > > > > thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", tz->temperature);
> > > > > thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d", trip);
> > > > > thermal_prop[3] = kasprintf(GFP_KERNEL, "EVENT=%d", tz->notify_event);
> > > > > thermal_prop[4] = NULL;
> > > > > kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop);
> > > > > for (i = 0; i < 4; ++i)
> > > > > kfree(thermal_prop[i]);
> > > > > mutex_unlock(&tz->lock);
> > > > > return 0;
> > > > > }
> > > > >
> > > > > drivers/thermal/user_space.c:48:52: error: passing 'char *[5]' to parameter of type 'const char *const *' discards qualifiers in nested pointer types [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
> > > > > kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop);
> > > > > ^~~~~~~~~~~~
> > > > > include/linux/kobject.h:238:22: note: passing argument to parameter 'envp' here
> > > > > const char *const envp[]);
> > > > > ^
> > > > >
> > > > > http://c-faq.com/ansi/constmismatch.html explains why it fails.
> > > > >
> > > > Interesting. One never stops learning. So the best you could do would
> > > > be char * const envp[], but I guess that doesn't help much.
> > >
> > > Yeah, I went down this path a year or so ago and had to give it up as
> > > well :(
> >
> > Well, the signature could still be changed as Guenter suggests.
> >
> > And the array being added in the new code could still be static.
> > After all, there isn't really any danger that the contents of those
> > strings will be modified, right? It's just that the const modifiers
> > weren't put in until it was too late and there were too many existing
> > callers. Perhaps a comment about this could be included in the
> > kerneldoc for kobject_uevent_env.
>
> I am all for changing this, but I remember I tried to, and somehow
> failed, but I don't remember the full details sorry, it was a while ago.
> If someone figures out how to make this all const, I will gladly take
> that patch.
>
Well we could use varargs...
int kobject_uevent_env(struct kobject *kobj,
enum kobject_action action,
...);
This will accept both const char* and char *.
Example https://repl.it/@RaulRangel/Const-char-var-args
It seems like most callers have a fixed number of env params, so you
wouldn't need a function that takes a list.
> thanks,
>
> greg k-h
next prev reply other threads:[~2019-04-18 15:29 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-17 19:03 [v3] usb/hcd: Send a uevent signaling that the host controller had died Raul E Rangel
2019-04-17 19:03 ` [PATCH v3] " Raul E Rangel
2019-04-17 19:14 ` [v3] " Alan Stern
2019-04-17 19:14 ` [PATCH v3] " Alan Stern
2019-04-17 20:20 ` [v3] " Raul E Rangel
2019-04-17 20:20 ` [PATCH v3] " Raul Rangel
2019-04-17 20:39 ` [v3] " Alan Stern
2019-04-17 20:39 ` [PATCH v3] " Alan Stern
2019-04-17 22:10 ` [v3] " Raul E Rangel
2019-04-17 22:10 ` [PATCH v3] " Raul Rangel
2019-04-17 22:23 ` [v3] " Guenter Roeck
2019-04-17 22:23 ` [PATCH v3] " Guenter Roeck
2019-04-17 22:41 ` [v3] " Raul E Rangel
2019-04-17 22:41 ` [PATCH v3] " Raul Rangel
2019-04-17 23:20 ` [v3] " Guenter Roeck
2019-04-17 23:20 ` [PATCH v3] " Guenter Roeck
2019-04-18 6:51 ` [v3] " Greg Kroah-Hartman
2019-04-18 6:51 ` [PATCH v3] " Greg Kroah-Hartman
2019-04-18 14:21 ` [v3] " Alan Stern
2019-04-18 14:21 ` [PATCH v3] " Alan Stern
2019-04-18 14:30 ` [v3] " Greg Kroah-Hartman
2019-04-18 14:30 ` [PATCH v3] " Greg Kroah-Hartman
2019-04-18 15:29 ` Raul E Rangel [this message]
2019-04-18 15:29 ` Raul Rangel
2019-04-18 20:59 ` kbuild test robot
2019-04-18 21:35 ` kbuild test robot
2019-04-19 12:16 ` [v3] " Greg Kroah-Hartman
2019-04-19 12:16 ` [PATCH v3] " Greg Kroah-Hartman
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=20190418152902.GA185502@google.com \
--to=rrangel@chromium.org \
--cc=bigeasy@linutronix.de \
--cc=djkurtz@chromium.org \
--cc=dtor@chromium.org \
--cc=gregkh@linuxfoundation.org \
--cc=groeck@chromium.org \
--cc=groeck@google.com \
--cc=gustavo@embeddedor.com \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=martin.blumenstingl@googlemail.com \
--cc=mathias.nyman@linux.intel.com \
--cc=miquel.raynal@bootlin.com \
--cc=oneukum@suse.com \
--cc=stern@rowland.harvard.edu \
--cc=zwisler@chromium.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;
as well as URLs for NNTP newsgroup(s).