Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1225533

Re: First kernel patch (optimization)

From Felipe Balbi <balbi@ti.com>
Newsgroups linux.kernel
Subject Re: First kernel patch (optimization)
Date 2015-09-15 22:20 +0200
Message-ID <q94RR-7te-13@gated-at.bofh.it> (permalink)
References <q94yv-6L6-17@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Tue, Sep 15, 2015 at 08:53:28PM +0100, Eric Curtin wrote:
> My first kernel patch, hope I did everything correctly! Instead of calling strlen on every iteration of the for loop, just call it once instead and store in a variable.

this should be broken up at 72 characters. Also, your subject and commit
log make no sense from a project history perspective. You don't need to
mention it's your first patch, just go straight to the details.

For the subject, I'd use something like:

tools: usbip: detach: avoid calling strlen() at each iteration

and for the commit log:

Instead of calling strlen() on every iterations of the for loop,
just call it once and cache the result in a temporary local variable
which will be used in the for loop instead.

cheers

> Signed-off-by: Eric Curtin <ericcurtin17@gmail.com>
> 
> diff --git a/tools/usb/usbip/src/usbip_detach.c b/tools/usb/usbip/src/usbip_detach.c
> index 05c6d15..9db9d21 100644
> --- a/tools/usb/usbip/src/usbip_detach.c
> +++ b/tools/usb/usbip/src/usbip_detach.c
> @@ -47,7 +47,9 @@ static int detach_port(char *port)
>  	uint8_t portnum;
>  	char path[PATH_MAX+1];
>  
> -	for (unsigned int i = 0; i < strlen(port); i++)
> +	unsigned int port_len = strlen(port);
> +
> +	for (unsigned int i = 0; i < port_len; i++)
>  		if (!isdigit(port[i])) {
>  			err("invalid port %s", port);
>  			return -1;
> 
> --
> 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/

-- 
balbi

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

First kernel patch (optimization) Eric Curtin <ericcurtin17@gmail.com> - 2015-09-15 22:00 +0200
  Re: First kernel patch (optimization) Felipe Balbi <balbi@ti.com> - 2015-09-15 22:20 +0200
  Re: First kernel patch (optimization) Steve Calfee <stevecalfee@gmail.com> - 2015-09-16 02:10 +0200
    Re: First kernel patch (optimization) Austin S Hemmelgarn <ahferroin7@gmail.com> - 2015-09-16 13:50 +0200
      RE: First kernel patch (optimization) David Laight <David.Laight@ACULAB.COM> - 2015-09-16 15:00 +0200
        Re: First kernel patch (optimization) Jaime Arrocha <jarr@innercoder.com> - 2015-09-17 04:10 +0200
          RE: First kernel patch (optimization) David Laight <David.Laight@ACULAB.COM> - 2015-09-17 10:50 +0200
      Re: First kernel patch (optimization) Greg KH <gregkh@linuxfoundation.org> - 2015-09-16 15:40 +0200
        Re: First kernel patch (optimization) Eric Curtin <ericcurtin17@gmail.com> - 2015-09-16 18:10 +0200
          Re: First kernel patch (optimization) Theodore Ts'o <tytso@mit.edu> - 2015-09-16 18:50 +0200
            Re: First kernel patch (optimization) Raymond Jennings <shentino@gmail.com> - 2015-09-16 19:30 +0200
            Re: First kernel patch (optimization) Josh Boyer <jwboyer@fedoraproject.org> - 2015-09-16 19:30 +0200
              Re: First kernel patch (optimization) Theodore Ts'o <tytso@mit.edu> - 2015-09-18 05:20 +0200
                Re: First kernel patch (optimization) Greg KH <gregkh@linuxfoundation.org> - 2015-09-18 09:50 +0200
                Re: First kernel patch (optimization) Raymond Jennings <shentino@gmail.com> - 2015-09-18 11:40 +0200
                Re: First kernel patch (optimization) Austin S Hemmelgarn <ahferroin7@gmail.com> - 2015-09-18 21:10 +0200
                Re: First kernel patch (optimization) Theodore Ts'o <tytso@mit.edu> - 2015-09-19 04:30 +0200
                Re: First kernel patch (optimization) Sudip Mukherjee <sudipm.mukherjee@gmail.com> - 2015-09-19 06:30 +0200
                Re: First kernel patch (optimization) Greg KH <gregkh@linuxfoundation.org> - 2015-09-19 07:20 +0200
                Re: First kernel patch (optimization) Theodore Ts'o <tytso@mit.edu> - 2015-09-19 14:30 +0200
                Re: First kernel patch (optimization) Alexander Holler <holler@ahsoftware.de> - 2015-09-19 15:00 +0200
                Re: First kernel patch (optimization) Alexander Holler <holler@ahsoftware.de> - 2015-09-19 16:20 +0200
                Re: First kernel patch (optimization) Theodore Ts'o <tytso@mit.edu> - 2015-09-19 16:30 +0200
                Re: First kernel patch (optimization) Alexander Holler <holler@ahsoftware.de> - 2015-09-19 19:50 +0200
                Re: First kernel patch (optimization) Theodore Ts'o <tytso@mit.edu> - 2015-09-20 04:30 +0200
                Re: First kernel patch (optimization) Alexander Holler <holler@ahsoftware.de> - 2015-09-20 12:50 +0200
                Re: First kernel patch (optimization) Austin S Hemmelgarn <ahferroin7@gmail.com> - 2015-09-21 17:50 +0200
                Re: First kernel patch (optimization) Alexander Holler <holler@ahsoftware.de> - 2015-09-21 19:30 +0200
                Re: First kernel patch (optimization) Alexander Holler <holler@ahsoftware.de> - 2015-09-21 20:50 +0200
          Re: First kernel patch (optimization) Greg KH <gregkh@linuxfoundation.org> - 2015-09-16 22:10 +0200
            Re: First kernel patch (optimization) Eric Curtin <ericcurtin17@gmail.com> - 2015-09-16 22:30 +0200
              Re: First kernel patch (optimization) Greg KH <gregkh@linuxfoundation.org> - 2015-09-17 00:40 +0200

csiph-web