lkml.org 
[lkml]   [2020]   [Aug]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    SubjectRE: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs
    Date
    From: Joe Perches
    > Sent: 27 August 2020 21:30
    ...
    > Perhaps what's necessary is to find any
    > appropriate .show function and change
    > any use of strcpy/sprintf within those
    > function to some other name.
    >
    > For instance:
    >
    > drivers/isdn/mISDN/core.c-static ssize_t name_show(struct device *dev,
    > drivers/isdn/mISDN/core.c- struct device_attribute *attr, char *buf)
    > drivers/isdn/mISDN/core.c-{
    > drivers/isdn/mISDN/core.c: strcpy(buf, dev_name(dev));
    > drivers/isdn/mISDN/core.c- return strlen(buf);
    > drivers/isdn/mISDN/core.c-}
    > drivers/isdn/mISDN/core.c-static DEVICE_ATTR_RO(name);

    That form ends up calculating the string length twice.
    Better would be:
    len = strlen(msg);
    memcpy(buf, msg, len);
    return len;


    David

    -
    Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
    Registration No: 1397386 (Wales)

    \
     
     \ /
      Last update: 2020-08-28 00:04    [W:4.242 / U:1.048 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site