Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1594322
| Path | csiph.com!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | Guenter Roeck <linux@roeck-us.net> |
| Newsgroups | linux.kernel |
| Subject | Re: Question about hwmon_attr_show_string |
| Date | Tue, 07 Mar 2017 16:10:01 +0100 |
| Message-ID | <tioUp-PI-7@gated-at.bofh.it> (permalink) |
| References | <tgJqh-1AZ-1@gated-at.bofh.it> <ti7JU-5av-21@gated-at.bofh.it> <tiaHL-7eE-3@gated-at.bofh.it> <tijrH-5mG-1@gated-at.bofh.it> |
| Dkim-Signature | v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:Cc:References:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=8TLEt/1wWfR3YmVo3ZUbAK6zsV3duppgHdX4+kNq5s8=; b=ZinTtYU2EZldb+nh9b+U8sKPY3 y6AmKubg0XKEnLY6DHlzn1ctRZF10eWqtPw+Z2N29NgdZ+0V0EJ2vdDGKWbuheZ/sqCcuTKekfYfy ByiIyBfn2jMwc8/wg0me1NpGPcFz3xl8cvZr+19qBUgHsgusShBX3G2bq4kwnHN2tX2WS/5y4ayc0 4PkNElSgbH5w7+6EyGlnLbTDTukU6onIzXMsfZmsRG03dFUsggSmbk5oN2IHFVIgPBUqtocCdsKvA A9NrfF3dh8fFfG8ZA3h6dy3rJjNRggsIiLP5MSB83jfA2sIsHbgktXTvPAt3bRzPEWmtfGDgLQ+5I cDcqjELw==; |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Authenticated_Sender | linux@roeck-us.net |
| X-Outgoing-Spam-Status | No, score=-1.0 |
| X-Antiabuse | This header was added to track abuse, please include it with any abuse report |
| X-Antiabuse | Primary Hostname - bh-25.webhostbox.net |
| X-Antiabuse | Original Domain - vger.kernel.org |
| X-Antiabuse | Originator/Caller UID/GID - [47 12] / [47 12] |
| X-Antiabuse | Sender Address Domain - roeck-us.net |
| X-Get-Message-Sender-Via | bh-25.webhostbox.net: authenticated_id: linux@roeck-us.net |
| X-Authenticated-Sender | bh-25.webhostbox.net: linux@roeck-us.net |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 65 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | Peter Hüwe <PeterHuewe@gmx.de>, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org |
| X-Original-Date | Tue, 7 Mar 2017 06:16:15 -0800 |
| X-Original-Message-ID | <333a9a55-e6d3-97ed-6223-6d09cb5d3c03@roeck-us.net> |
| X-Original-References | <201703030133.01363.PeterHuewe@gmx.de> <201703062148.36101.PeterHuewe@gmx.de> <20170306234755.GA16512@roeck-us.net> <20170307100846.0487135b@endymion> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1594322 |
Show key headers only | View raw
On 03/07/2017 01:08 AM, Jean Delvare wrote:
> 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.
>
> Signed-off-by: Jean Delvare <jdelvare@suse.de>
Makes sense. I'll add it to -next.
Thanks,
Guenter
> ---
> 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);
> };
>
>
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
Conversion of w83627ehf to hwmon_device_register_with_info ? Peter Hüwe <PeterHuewe@gmx.de> - 2017-03-03 01:40 +0100
Re: Conversion of w83627ehf to hwmon_device_register_with_info ? Guenter Roeck <linux@roeck-us.net> - 2017-03-03 04:00 +0100
Re: Conversion of w83627ehf to hwmon_device_register_with_info ? Jean Delvare <jdelvare@suse.de> - 2017-03-03 16:10 +0100
Question about hwmon_attr_show_string Peter Hüwe <PeterHuewe@gmx.de> - 2017-03-06 21:50 +0100
Re: Question about hwmon_attr_show_string Guenter Roeck <linux@roeck-us.net> - 2017-03-07 01:00 +0100
Re: Question about hwmon_attr_show_string Jean Delvare <jdelvare@suse.de> - 2017-03-07 10:20 +0100
Re: Question about hwmon_attr_show_string Peter Huewe <peterhuewe@gmx.de> - 2017-03-07 10:30 +0100
Re: Question about hwmon_attr_show_string Guenter Roeck <linux@roeck-us.net> - 2017-03-07 16:10 +0100
csiph-web