lkml.org 
[lkml]   [2007]   [Mar]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [RFC][PATCH] Apple SMC driver (hardware monitoring and control)
    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.
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2007-03-14 15:03    [W:0.039 / U:117.996 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site