From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752053AbbIOULy (ORCPT ); Tue, 15 Sep 2015 16:11:54 -0400 Received: from arroyo.ext.ti.com ([192.94.94.40]:51688 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751848AbbIOULx (ORCPT ); Tue, 15 Sep 2015 16:11:53 -0400 Date: Tue, 15 Sep 2015 15:11:48 -0500 From: Felipe Balbi To: Eric Curtin CC: , , , Subject: Re: First kernel patch (optimization) Message-ID: <20150915201148.GU19948@saruman.tx.rr.com> Reply-To: References: <1442346808-3784-1-git-send-email-ericcurtin17@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="qxpYSgLynlcP4boX" Content-Disposition: inline In-Reply-To: <1442346808-3784-1-git-send-email-ericcurtin17@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --qxpYSgLynlcP4boX Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Sep 15, 2015 at 08:53:28PM +0100, Eric Curtin wrote: > My first kernel patch, hope I did everything correctly! Instead of callin= g 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 >=20 > diff --git a/tools/usb/usbip/src/usbip_detach.c b/tools/usb/usbip/src/usb= ip_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]; > =20 > - for (unsigned int i =3D 0; i < strlen(port); i++) > + unsigned int port_len =3D strlen(port); > + > + for (unsigned int i =3D 0; i < port_len; i++) > if (!isdigit(port[i])) { > err("invalid port %s", port); > return -1; >=20 > -- > 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/ --=20 balbi --qxpYSgLynlcP4boX Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJV+HuEAAoJEIaOsuA1yqRE3MwP/iRa0tQJwPjlzPECHugbMzcl 3HkqIkW3kCw1QECLHemGA6mqf+2e9DvYw77y3m5xM8FB1YrqI2JpdZl7UKc9QNbE qR3+mgA+LAWE1rzbIT3xo0b0BN0wSJUWC3mSOGffrraPds04pgyutTSGT9URof35 +XQz3nsTzBhm+G2ui7k861iQXukvxixqQMOBet7UBV99pzE+ounFczyvwcBl9Xuj 4R1zqE2rLdafzk6BGfkyM0wXTVXE4srgNmVOLDuMyC9Nj/HoaOq5Z6Jg6LASh0Dl LAKYg+c3+n7/UWPiUHNKFfGZuQdvuCBe8wLnBaJLIxQqgL8rT8jR8UEzxm7vWDyC JAmvJGiZ7/aSC43qieoH9TzMiSkV98J5Ld6uF6FxJRBaqkO6ADt/fF/kvd4cCJOs UuupnOcS6SURlU0nXOC7c0NRzKQGFPnIkmt+fOZrWXSOU2IfUP54tYY6yzn5VX6n VQVVd8cxpoH2x/HmzR1qjy5+vbyN0cS8//MTNtfGIae9I2zeb0VH7/j27uHO7hDY 8ckotkBFFu9ySEkXJCeMecatd4E6A0GiU5HYVHhp3M8fKM5ZRwMtzA+A+i91dDt+ OzgBHqopQUAB1s/9bTyERla3FpMW0OF5Fo7D4sDNyv/7LeO05wfsXS/YiXOICZr4 wTWePyL6zW8bXnvfV98G =6bgR -----END PGP SIGNATURE----- --qxpYSgLynlcP4boX--