From: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Kees Cook <keescook@chromium.org>,
Andrew Morton <akpm@linux-foundation.org>,
Duncan Sands <duncan.sands@free.fr>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC 7/7] USB: usbatm: avoid fragile and inefficient snprintf use
Date: Wed, 9 Mar 2016 16:08:34 +0300 [thread overview]
Message-ID: <56E02052.80507@cogentembedded.com> (raw)
In-Reply-To: <1457469654-17059-8-git-send-email-linux@rasmusvillemoes.dk>
Hello.
On 3/8/2016 11:40 PM, Rasmus Villemoes wrote:
> Passing overlapping source and destination is fragile, and in this
> case we can even simplify the code and avoid the huge stack buffer by
> using the %p extension for printing a small hex dump.
>
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
> drivers/usb/atm/usbatm.c | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
> index db322d9ccb6e..fb47f9883056 100644
> --- a/drivers/usb/atm/usbatm.c
> +++ b/drivers/usb/atm/usbatm.c
> @@ -1331,15 +1331,12 @@ MODULE_VERSION(DRIVER_VERSION);
> static int usbatm_print_packet(struct usbatm_data *instance,
> const unsigned char *data, int len)
> {
> - unsigned char buffer[256];
> - int i = 0, j = 0;
> + int i, j;
>
> for (i = 0; i < len;) {
> - buffer[0] = '\0';
> - sprintf(buffer, "%.3d :", i);
> - for (j = 0; (j < 16) && (i < len); j++, i++)
> - sprintf(buffer, "%s %2.2x", buffer, data[i]);
> - dev_dbg(&instance->usb_intf->dev, "%s", buffer);
> + j = min(16, len-i);
Kernel style assumes spaces on either side of the operators, like below, no?
> + dev_dbg(&instance->usb_intf->dev, "%.3d : %*ph", i, j, data + i);
> + i += j;
> }
> return i;
> }
MBR, Sergei
next prev parent reply other threads:[~2016-03-09 13:08 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-05 20:38 snprintf, overlapping destination and source Rasmus Villemoes
2015-12-05 20:42 ` Julia Lawall
2015-12-07 22:04 ` Kees Cook
2015-12-16 13:14 ` Rasmus Villemoes
2016-03-08 20:40 ` [RFC 0/7] eliminate snprintf with overlapping src and dst Rasmus Villemoes
2016-03-08 20:40 ` [RFC 1/7] drm/amdkfd: avoid fragile and inefficient snprintf use Rasmus Villemoes
2016-03-14 14:33 ` Oded Gabbay
2016-03-14 14:33 ` Oded Gabbay
2016-03-14 19:18 ` Rasmus Villemoes
2016-03-14 19:18 ` Rasmus Villemoes
2016-03-08 20:40 ` [RFC 2/7] Input: joystick - avoid fragile " Rasmus Villemoes
2016-03-09 6:49 ` Andy Shevchenko
2016-03-08 20:40 ` [RFC 3/7] leds: avoid fragile sprintf use Rasmus Villemoes
2016-03-08 20:40 ` [RFC 4/7] drivers/media/pci/zoran: avoid fragile snprintf use Rasmus Villemoes
2016-03-08 20:40 ` [RFC 5/7] wlcore: " Rasmus Villemoes
2016-03-08 20:40 ` Rasmus Villemoes
2016-03-09 11:49 ` Kalle Valo
2016-03-08 20:40 ` [RFC 6/7] [media] ati_remote: " Rasmus Villemoes
2016-03-08 20:40 ` [RFC 7/7] USB: usbatm: avoid fragile and inefficient " Rasmus Villemoes
2016-03-08 21:01 ` Joe Perches
2016-03-10 23:56 ` Greg Kroah-Hartman
2016-03-09 13:08 ` Sergei Shtylyov [this message]
2016-03-08 23:07 ` [RFC 0/7] eliminate snprintf with overlapping src and dst Kees Cook
2016-03-08 23:13 ` Kees Cook
2016-03-09 6:51 ` Andy Shevchenko
2016-03-09 20:49 ` Andrew Morton
2016-03-09 22:19 ` Rasmus Villemoes
2016-03-10 13:59 ` One Thousand Gnomes
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=56E02052.80507@cogentembedded.com \
--to=sergei.shtylyov@cogentembedded.com \
--cc=akpm@linux-foundation.org \
--cc=duncan.sands@free.fr \
--cc=gregkh@linuxfoundation.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.