From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751843AbbBMFNn (ORCPT ); Fri, 13 Feb 2015 00:13:43 -0500 Received: from bh-25.webhostbox.net ([208.91.199.152]:56106 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751236AbbBMFNm (ORCPT ); Fri, 13 Feb 2015 00:13:42 -0500 Message-ID: <54DD87FF.7070803@roeck-us.net> Date: Thu, 12 Feb 2015 21:13:35 -0800 From: Guenter Roeck User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Rasmus Villemoes , Henrik Rydberg , Jean Delvare CC: lm-sensors@lm-sensors.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] hwmon: (applesmc) Allow format checking References: <1423750517-26439-1-git-send-email-linux@rasmusvillemoes.dk> In-Reply-To: <1423750517-26439-1-git-send-email-linux@rasmusvillemoes.dk> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Authenticated_sender: linux@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-CTCH-PVer: 0000001 X-CTCH-Spam: Unknown X-CTCH-VOD: Unknown X-CTCH-Flags: 0 X-CTCH-RefID: str=0001.0A020203.54DD8805.0115,ss=1,re=0.001,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 X-CTCH-Score: 0.001 X-CTCH-ScoreCust: 0.000 X-CTCH-Rules: C_4847, X-CTCH-SenderID: linux@roeck-us.net X-CTCH-SenderID-Flags: 0 X-CTCH-SenderID-TotalMessages: 8 X-CTCH-SenderID-TotalSpam: 0 X-CTCH-SenderID-TotalSuspected: 0 X-CTCH-SenderID-TotalConfirmed: 0 X-CTCH-SenderID-TotalBulk: 0 X-CTCH-SenderID-TotalVirus: 0 X-CTCH-SenderID-TotalRecipients: 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: mailgid no entry from get_relayhosts_entry 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 On 02/12/2015 06:15 AM, Rasmus Villemoes wrote: > Currently gcc and other tools can't check the format strings. It's > easy to fix by letting fan_speed_fmt simply hold what is different > between the strings (and renaming it appropriately). While at it, we > can also eliminate some wasted space and an extra level of indirection > by making it an array of char[4] instead of char*. > > Signed-off-by: Rasmus Villemoes Saving a few bytes with the added cost of harder to understand code. Not really sure if that is worth it. I'll need to see a Tested-by: for this patch. Also, please fix the checkpatch warnings. Thanks, Guenter > --- > drivers/hwmon/applesmc.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c > index 0af63da6b603..0c950e1b03f3 100644 > --- a/drivers/hwmon/applesmc.c > +++ b/drivers/hwmon/applesmc.c > @@ -84,12 +84,12 @@ > #define TEMP_SENSOR_TYPE "sp78" > > /* List of keys used to read/write fan speeds */ > -static const char *const fan_speed_fmt[] = { > - "F%dAc", /* actual speed */ > - "F%dMn", /* minimum speed (rw) */ > - "F%dMx", /* maximum speed */ > - "F%dSf", /* safe speed - not all models */ > - "F%dTg", /* target speed (manual: rw) */ > +static const char fan_speed_suffix[][4] = { > + "Ac", /* actual speed */ > + "Mn", /* minimum speed (rw) */ > + "Mx", /* maximum speed */ > + "Sf", /* safe speed - not all models */ > + "Tg", /* target speed (manual: rw) */ > }; > > #define INIT_TIMEOUT_MSECS 5000 /* wait up to 5s for device init ... */ > @@ -811,7 +811,7 @@ static ssize_t applesmc_show_fan_speed(struct device *dev, > char newkey[5]; > u8 buffer[2]; > > - sprintf(newkey, fan_speed_fmt[to_option(attr)], to_index(attr)); > + sprintf(newkey, "F%d%s", to_index(attr), fan_speed_suffix[to_option(attr)]); > > ret = applesmc_read_key(newkey, buffer, 2); > speed = ((buffer[0] << 8 | buffer[1]) >> 2); > @@ -834,7 +834,7 @@ static ssize_t applesmc_store_fan_speed(struct device *dev, > if (kstrtoul(sysfsbuf, 10, &speed) < 0 || speed >= 0x4000) > return -EINVAL; /* Bigger than a 14-bit value */ > > - sprintf(newkey, fan_speed_fmt[to_option(attr)], to_index(attr)); > + sprintf(newkey, "F%d%s", to_index(attr), fan_speed_suffix[to_option(attr)]); > > buffer[0] = (speed >> 6) & 0xff; > buffer[1] = (speed << 2) & 0xff; >