Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755154AbdCGJZD convert rfc822-to-8bit (ORCPT ); Tue, 7 Mar 2017 04:25:03 -0500 Received: from mout.gmx.net ([212.227.17.21]:50003 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751838AbdCGJXr (ORCPT ); Tue, 7 Mar 2017 04:23:47 -0500 Date: Tue, 07 Mar 2017 10:14:21 +0100 User-Agent: K-9 Mail for Android In-Reply-To: <20170307100846.0487135b@endymion> References: <201703030133.01363.PeterHuewe@gmx.de> <201703062148.36101.PeterHuewe@gmx.de> <20170306234755.GA16512@roeck-us.net> <20170307100846.0487135b@endymion> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Subject: Re: Question about hwmon_attr_show_string To: Jean Delvare , Guenter Roeck CC: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org From: Peter Huewe Message-ID: <14C0030C-C764-45AE-BA2D-881051004490@gmx.de> X-Provags-ID: V03:K0:vFkwJoOSuOiJLdQx6LWG1knpxOp+J7hKNjwhsEiR39AoeORy2OO /SVSN/5eqswFN86V2AsJ4rSsJbRmUdOo7y8jl6sL5z0ms1Yc2xwAt3REK7gx2RDkN5mfn9i 5NF7JnEAMc5CV2VOVBDf/+zburNgvQ3nTtXsz2Bo7UUQ68Ncl0rhdj2XuEo8i3oRhsfmAtq LnR0SuktULbVtAkiPn+fQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:HvEAr8OxDHc=:wOaAddrijTYWqjZjlq2L0f rrFPCn51mULJ5172IgGBZuzxYjE61MYK9Z/m4Jn8PlRz4SDx5Ud/EK78WYpBZhL6UVd1SJYAL 9zRb9XP4rMtcTWdcefi/LnGkyF+CI3lGXlXWOJUllLzLVtIWe3h/1hmVyXWXdTLUDlpaxWVdW c+ODfqEst3zQR/Q9AoLmnkt6Pxe+pjqcH9RQWjQ8ZAGYh5q3sIftcd8Bsl7b7A22JaJmVZ3Cu M0k6mpvuC9OYYuVGt2dslOe6NinjQ8gceAAjyzHbWiMNNgOkhw72b0JMwnYihECih6Isp9SU1 r2r2PWlvf8HpKu5jI1zNF8psy72SdHvpVmcbQJmn4Ngutqp5Abpw6oTjnhBr1dfgJu9xMSDNu UYkjoRNYKoQEKpRvmXUVBcb7nKoWnuQXh1P+D7nnW3MpXtEwkJUiu8fTxc3dYzSrjnlAXSo+w brTTY0yAos0vDdTcgpwXDL1dkI+Yc1ArIL9hSayWg0akU5goc3nfQ86Bw3SvxzJx6nhMRGClz R9yevUYJjPqJYVvCwK/EjjoI+/fny/c3Tmi/5yHk3A+SzrgZwNNZcF0Wwx184iRb6BAZKBpIe LnT91W1Bgj/oImSi4iu4yWkVODKT+kcT7N6uTkzIrIkbtSxRjPOAPM08DtE2z0Af6PBgbpge5 USrgT4TkMI51KESSWVcOts0AiJa2ZXDkvL8BpAKCsr1pmKdW3kOagPQUS9vTsQ7IrGwCwcaOT ASjxtgjGQwcH2JI83SYg4fVVrttLOHfaw36CjI7N74/pBjSArzmYMu5k8dMUQHy0cqIrlE4Px xVb+JzQ Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2574 Lines: 79 Am 7. März 2017 10:08:46 MEZ schrieb Jean Delvare : >Hi Guenter, > >On Mon, 6 Mar 2017 15:47:55 -0800, Guenter Roeck wrote: >> On Mon, Mar 06, 2017 at 09:48:35PM +0100, Peter Hüwe wrote: >> > Hi Guenter, >> > >> > I was wondering whether there was a particular reason why >> > hwmon_attr_show_string passes only an "empty" pointer(pointer) to >the ops- >> > >read_string function rather than the buffer itself? >> > >> > Wouldn't this mean that in ops->read_string I'd have to reserve >some space for >> > the value on the heap (and taking care to free it somewhere, since >returning >> > an address on the stack is bad idea), instead of calling >sprintf(buf, "%s\n", >> > s) directly? >> > >> > With the current implementation I have to sprintf it into my local >buffer and >> > you sprintf it again into the final buffer. >> >> The idea was that the called code would return a pointer to a >constant string, >> ie one that isn't changing from call to call. > >In that case, what about the following change? > >Subject: hwmon: Constify str parameter of hwmon_ops->read_string > >The read_string callback is supposed to retrieve a pointer to a >constant string. I would think that clarifies the situation and also gets rid warnings about dropping const qualifier at the point of assignment. Reviewed-by: Peter Huewe > >Signed-off-by: Jean Delvare >--- > drivers/hwmon/hwmon.c | 2 +- > include/linux/hwmon.h | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > >--- linux-4.10.orig/drivers/hwmon/hwmon.c 2017-02-19 23:34:00.000000000 >+0100 >+++ linux-4.10/drivers/hwmon/hwmon.c 2017-03-07 08:22:27.784527968 >+0100 >@@ -186,7 +186,7 @@ static ssize_t hwmon_attr_show_string(st > char *buf) > { > struct hwmon_device_attribute *hattr = to_hwmon_attr(devattr); >- char *s; >+ const char *s; > int ret; > > ret = hattr->ops->read_string(dev, hattr->type, hattr->attr, >--- linux-4.10.orig/include/linux/hwmon.h 2017-02-19 23:34:00.000000000 >+0100 >+++ linux-4.10/include/linux/hwmon.h 2017-03-07 08:21:28.247998585 >+0100 >@@ -336,7 +336,7 @@ struct hwmon_ops { > int (*read)(struct device *dev, enum hwmon_sensor_types type, > u32 attr, int channel, long *val); > int (*read_string)(struct device *dev, enum hwmon_sensor_types type, >- u32 attr, int channel, char **str); >+ u32 attr, int channel, const char **str); > int (*write)(struct device *dev, enum hwmon_sensor_types type, > u32 attr, int channel, long val); > }; -- Sent from my mobile