Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754052AbdCFXtw (ORCPT ); Mon, 6 Mar 2017 18:49:52 -0500 Received: from bh-25.webhostbox.net ([208.91.199.152]:51694 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753253AbdCFXtp (ORCPT ); Mon, 6 Mar 2017 18:49:45 -0500 Date: Mon, 6 Mar 2017 15:47:55 -0800 From: Guenter Roeck To: Peter =?iso-8859-1?Q?H=FCwe?= Cc: linux-hwmon@vger.kernel.org, Jean Delvare , linux-kernel@vger.kernel.org Subject: Re: Question about hwmon_attr_show_string Message-ID: <20170306234755.GA16512@roeck-us.net> References: <201703030133.01363.PeterHuewe@gmx.de> <201703062148.36101.PeterHuewe@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <201703062148.36101.PeterHuewe@gmx.de> User-Agent: Mutt/1.5.24 (2015-08-30) X-Authenticated_sender: guenter@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: guenter@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: guenter@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 882 Lines: 22 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. What attribute do you see that would require a dynamic (changing) string ? Thanks, Guenter