LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Nicolas Boichat <nicolas@boichat.ch>
To: Cong WANG <xiyou.wangcong@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [RFC][PATCH] Apple SMC driver (hardware monitoring and control)
Date: Thu, 15 Mar 2007 19:31:35 +0800	[thread overview]
Message-ID: <45F92E97.7030207@boichat.ch> (raw)
In-Reply-To: <2375c9f90703140700k9fb4606pad0f0dc401764323@mail.gmail.com>

Hello,

Cong WANG wrote:
> 2007/3/14, Cong WANG wrote:
>> I am sorry. I forgot to CC to the list.
>>
>> 2007/3/14, Nicolas Boichat wrote:
>> > Hello,
>> >
>>
>> <snip>
>>
>> > +static ssize_t applesmc_show_fan_manual(struct device *dev, char *buf,
>> > +                                                               int
>> offset)
>> > +{
>> > +       int ret;
>> > +       u16 manual = 0;
>> > +       u8 buffer[2];
>> > +
>> > +       down(&applesmc_sem);
>> > +
>> > +       ret = applesmc_read_key(FANS_MANUAL, buffer, 2);
>> > +       manual = ((buffer[0] << 8 | buffer[1]) >> offset) & 0x01;
>> > +
>> > +       up(&applesmc_sem);
>> > +       if (ret)
>> > +               return ret;
>> > +       else
>> > +               return sprintf(buf, "%d\n", manual);
>> > +}
>> > +
>>
>> I doubt about your last 'sprintf'. Your 'buf' just has only two 'u8's,
>> which maybe only has two bytes, and '\n' already consumes one. So only
>> one byte is left for the decimal vaule of 'manual'. Even it is just
>> less than 10, just as what you want, the final '\0' is omitted!
>>
>> What's more, you can't get such information from the return value of
>> 'sprintf'. So I suggest you to choose 'snprintf' instead.
>>
> 
> Sorry. I thought his 'buffer' as 'buf'. But my suggestion is still
> worthy your thinking.

I'm quite sure using sprintf is ok. At least it's the way sysfs helper
functions are coded in other parts of the kernel too.

I agree that the variable names (buf and buffer) used are quite
confusing though... I'll fix that.

Best regards,

Nicolas

  reply	other threads:[~2007-03-15 11:39 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-14  9:29 Nicolas Boichat
2007-03-14 11:11 ` Cong WANG
2007-03-14 14:00   ` Cong WANG
2007-03-15 11:31     ` Nicolas Boichat [this message]
2007-03-19  5:19 ` [PATCH] " Nicolas Boichat
2007-03-19  6:54   ` Andrew Morton
2007-03-19  7:35     ` Nicolas Boichat
2007-03-20  7:12     ` Nicolas Boichat
2007-03-22 15:37   ` Dmitry Torokhov
2007-04-09 13:53     ` [PATCH] Apple SMC driver - fix input device Nicolas Boichat
2007-04-09 15:17       ` Dmitry Torokhov
2007-04-09 20:04       ` Andrew Morton
2007-04-09 20:11         ` Dmitry Torokhov
2007-04-09 21:51         ` Paul Mackerras
2007-03-19 21:43 ` [RFC][PATCH] Apple SMC driver (hardware monitoring and control) Bob Copeland
2007-03-20  7:02   ` Nicolas Boichat
2007-03-20 15:14     ` Bob Copeland
2007-03-21  4:03     ` Bob Copeland
     [not found]     ` <eb4a44160703200016i74786682n41f87f3d88f90409@mail.gmail.com>
2007-04-14  8:05       ` [PATCH] applesmc - fix crash when activating a led trigger on the keyboard backlight Nicolas Boichat
2007-04-14  8:45         ` Richard Purdie
2007-04-14 13:31           ` [PATCH] applesmc - fix crash when activating a led trigger on the keyboard backlight - use a workqueue Nicolas Boichat
2007-03-20 10:08   ` [lm-sensors] [RFC][PATCH] Apple SMC driver (hardware monitoring and control) Jean Delvare
2007-03-22 10:36     ` Nicolas Boichat
2007-03-20 16:12 ` Gerb Stralko
2007-04-11 12:25 ` [lm-sensors] " Jean Delvare
2007-04-11 12:47   ` Nicolas Boichat
2007-04-13  5:33   ` [PATCH 1/2] Apple SMC driver - standardize and sanitize sysfs tree + minor features addition Nicolas Boichat
2007-04-13  6:38     ` [PATCH 2/2] Apple SMC driver - implement key enumeration Nicolas Boichat

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=45F92E97.7030207@boichat.ch \
    --to=nicolas@boichat.ch \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xiyou.wangcong@gmail.com \
    --subject='Re: [RFC][PATCH] Apple SMC driver (hardware monitoring and control)' \
    /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

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).