From patchwork Wed Dec 18 18:50:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Cooper X-Patchwork-Id: 3371341 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 245CA9F314 for ; Wed, 18 Dec 2013 18:52:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4B9E62017C for ; Wed, 18 Dec 2013 18:52:00 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EF7CB20179 for ; Wed, 18 Dec 2013 18:51:58 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VtMDZ-0000Zy-63; Wed, 18 Dec 2013 18:51:37 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VtMDR-0007qM-MH; Wed, 18 Dec 2013 18:51:29 +0000 Received: from mho-02-ewr.mailhop.org ([204.13.248.72]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VtMDP-0007ot-7b for linux-arm-kernel@lists.infradead.org; Wed, 18 Dec 2013 18:51:27 +0000 Received: from pool-108-39-110-144.nrflva.fios.verizon.net ([108.39.110.144] helo=titan) by mho-02-ewr.mailhop.org with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1VtMCz-00096y-Rf; Wed, 18 Dec 2013 18:51:01 +0000 Received: from titan.lakedaemon.net (localhost [127.0.0.1]) by titan (Postfix) with ESMTP id BA2664F60AE; Wed, 18 Dec 2013 13:50:58 -0500 (EST) X-Mail-Handler: Dyn Standard SMTP by Dyn X-Originating-IP: 108.39.110.144 X-Report-Abuse-To: abuse@dyndns.com (see http://www.dyndns.com/services/sendlabs/outbound_abuse.html for abuse reporting information) X-MHO-User: U2FsdGVkX1+ZxDvN2R5aMGMNowt10z4HYNQwaaMFrh8= X-DKIM: OpenDKIM Filter v2.0.1 titan BA2664F60AE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lakedaemon.net; s=mail; t=1387392658; bh=1qPbJTL1TJ+TvhGD6fGSXijYLkitXPfp1T6YdbjlgLU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:In-Reply-To; b=GLI0mjSQvjrr238nUwlQBIh/XREcSqnzFWwpeka9WLMdixe5wP8rRUKljMvDs+y0+ YeSfdkBmarw+64NSes2qfVg5U0Zirxz4L8b/uSS9arl2CjiOKWkenagcmIlqTitFUp u0jQZCx1YIK8v/8PbuoflwJYd1D2mAetMqwipUtOBGZyOTBDL5t/wFcy0MYUcbV7LP XUGNBCm2a4MyXRinMlpOXXEDZVyBGI0viR1u+b3Op1poaPk9UtT4ufNsShE+kxyYqU iQD3n/Z0GTDw/8kYSUJV0CRNeffUKDJiyLxhbARfqYxs15O2DMr72R+IiR2Ai/dGV0 3X0oYpTKOSDGw== Date: Wed, 18 Dec 2013 13:50:58 -0500 From: Jason Cooper To: Russell King - ARM Linux Subject: Re: [PATCH V2 2/8] string: fix strncmp function Message-ID: <20131218185058.GR2609@titan.lakedaemon.net> References: <1386767259-15693-1-git-send-email-p.wilczek@samsung.com> <1387368551-18958-1-git-send-email-p.wilczek@samsung.com> <1387368551-18958-3-git-send-email-p.wilczek@samsung.com> <20131218121551.GH4360@n2100.arm.linux.org.uk> <52B193BE.1080206@gmail.com> <20131218125203.GI4360@n2100.arm.linux.org.uk> <20131218160114.GP2609@titan.lakedaemon.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20131218160114.GP2609@titan.lakedaemon.net> User-Agent: Mutt/1.5.20 (2009-06-14) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131218_135127_307377_658D5F0F X-CRM114-Status: GOOD ( 26.16 ) X-Spam-Score: -2.0 (--) Cc: Nicolas Pitre , Piotr Wilczek , devicetree-discuss@lists.ozlabs.org, Daniel Mack , Kyungmin Park , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Dec 18, 2013 at 11:01:15AM -0500, Jason Cooper wrote: > On Wed, Dec 18, 2013 at 12:52:03PM +0000, Russell King - ARM Linux wrote: > > On Wed, Dec 18, 2013 at 01:23:26PM +0100, Daniel Mack wrote: > > > On 12/18/2013 01:15 PM, Russell King - ARM Linux wrote: > > > > For instance, can you be sure that there aren't any uses of strncmp() > > > > which already test for less-than-zero etc? > > > > > > In this case, yes. The code as it stands is very small, and users only > > > check for the return value of these functions to be 0. > > > > > > But I wonder whether that patch is needed at all. At least the rest of > > > this series does not even seem to introduce new call sites of strcmp() > > > or strncmp() ... > > > > The implementation appears to be buggy as it stands - all it does is > > sum up the differences in the whole string. > > > > What if you're comparing two strings: > > > > ac > > ca > > > > The first character has a difference of +2, the second has a difference > > of -2. Sum those together and you get zero. Oh, the two strings are > > identical! > > Yes, you are correct, the implementation isn't perfect. I'll correct it > since I introduced it. I've pushed the following: -------8<--------------------------------- commit c3da82f0caa50c0efadbd6f129a326dda3fe3dec Author: Jason Cooper Date: Wed Dec 18 18:24:43 2013 +0000 string: use kernel version of strncmp() Signed-off-by: Jason Cooper diff --git a/string.c b/string.c index 5105490143c8..629c281f3abd 100644 --- a/string.c +++ b/string.c @@ -18,14 +18,18 @@ int strlen(const char *str) int strncmp(const char *stra, const char *strb, int len) { - int diff=0; - const char *a = stra; - const char *b = strb; - - while ((a - stra) < len) - diff += *a++ - *b++; - - return diff; + unsigned char c1, c2; + + while (len) { + c1 = *stra++; + c2 = *strb++; + if (c1 != c2) + return c1 < c2 ? -1 : 1; + if (!c1) + break; + len--; + } + return 0; } void *gethexaddr(const char *str, const char **end)