From patchwork Thu Dec 4 10:30:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 417705 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 31E1C1400D5 for ; Thu, 4 Dec 2014 21:31:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753947AbaLDKbH (ORCPT ); Thu, 4 Dec 2014 05:31:07 -0500 Received: from mail-la0-f45.google.com ([209.85.215.45]:52729 "EHLO mail-la0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753385AbaLDKbF (ORCPT ); Thu, 4 Dec 2014 05:31:05 -0500 Received: by mail-la0-f45.google.com with SMTP id gq15so13963409lab.4 for ; Thu, 04 Dec 2014 02:31:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id; bh=yv2tCALLDIpwhJZ2gib9/qkdQLfhiSx/ZEpsK5VfEyI=; b=L++b6tKqoz7A/uXgrEPmCE3ARSZjE0mywjh/VahpBBeI/mSSxaJzb4ZfvXMCW5P33T l84zrBw5q2z2XEGmKe1zO03ukLznwq+qTAzxBp6pGKdAclGVFa6D9NL7Cev57Z9/j69M +Q0hXFknOk3+Db8OueTo8Ue32sh5Bb07zI3bM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=yv2tCALLDIpwhJZ2gib9/qkdQLfhiSx/ZEpsK5VfEyI=; b=eyoG3Akt6A5TuJ27ZU+sbHXtWZMxmuP6JGt3vhrSFzb2z88Iq1xq5prVWFrpqeb88Y Iyeb2r9s3VJx9IhnV61qPby59pX9dS+IRacnyS+9Q9Bf/6knK+2GfJRZrWHicHLj2eET f6zVbVELzPKupP6iwU9x1XERHngZiriScJYBuPArum+V0kuXSgpZ9Ee6DYGmC9EuVVUv /6i3iz/BqNvSbAwZC+Z87Z4bU7jpiVYFSSjPiRRMiCjT8dlqTkYrKO0F+kOHAkNjv5x5 UK/pTAPqGp9Kwh3yM2jphnH5ksXElwklg5wwTtYwxU+yQqngAfv+NBkeyJxYES35yT/j vLdA== X-Gm-Message-State: ALoCoQlhCUl+9dwbGHTR6u8N76GHl+Rx/yaj5Y5aYyQ9f7giGmKnlwBPFbSKNWogO7rcwcmLA4lr X-Received: by 10.112.145.37 with SMTP id sr5mr9017185lbb.76.1417689063791; Thu, 04 Dec 2014 02:31:03 -0800 (PST) Received: from spencer.imf.au.dk ([130.225.20.51]) by mx.google.com with ESMTPSA id nb7sm7187007lbb.43.2014.12.04.02.31.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Dec 2014 02:31:03 -0800 (PST) From: Rasmus Villemoes To: Grant Grundler Cc: Rasmus Villemoes , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] net: tulip: Remove private "strncmp" Date: Thu, 4 Dec 2014 11:30:40 +0100 Message-Id: <1417689040-14958-1-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.0.4 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The comment says that the built-in strncmp didn't work. That is not surprising, as apparently "str" semantics are not really what is wanted (hint: de4x5_strncmp only stops when two different bytes are encountered or the end is reached; not if either byte happens to be 0). de4x5_strncmp is actually a memcmp (except for the signature and that bytes are not necessarily treated as unsigned char); since only the boolean value of the result is used we can just replace de4x5_strncmp with memcmp. Signed-off-by: Rasmus Villemoes Acked-by: Grant Grundler --- Notes: I don't know if the comment meant to say 3 bytes, or if the code compares meaningful chunks of memory (the first three bytes of &lp->srom span 1.5 fields, and the three bytes from (char*)&lp->srom + 0x10 are &lp->srom.{id_block_crc,reserved2,version} - it seems odd that these chunks should ever be equal to each other and to the enet_det[i]). Whether or not the current code works, this patch shouldn't change the semantics, and I'd like to get rid of de4x5_strncmp since it is not, in fact, a strncmp. drivers/net/ethernet/dec/tulip/de4x5.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c index cf8b6ff..badff18 100644 --- a/drivers/net/ethernet/dec/tulip/de4x5.c +++ b/drivers/net/ethernet/dec/tulip/de4x5.c @@ -995,7 +995,6 @@ static void de4x5_dbg_mii(struct net_device *dev, int k); static void de4x5_dbg_media(struct net_device *dev); static void de4x5_dbg_srom(struct de4x5_srom *p); static void de4x5_dbg_rx(struct sk_buff *skb, int len); -static int de4x5_strncmp(char *a, char *b, int n); static int dc21041_infoleaf(struct net_device *dev); static int dc21140_infoleaf(struct net_device *dev); static int dc21142_infoleaf(struct net_device *dev); @@ -4102,8 +4101,7 @@ get_hw_addr(struct net_device *dev) } /* -** Test for enet addresses in the first 32 bytes. The built-in strncmp -** didn't seem to work here...? +** Test for enet addresses in the first 32 bytes. */ static int de4x5_bad_srom(struct de4x5_private *lp) @@ -4111,8 +4109,8 @@ de4x5_bad_srom(struct de4x5_private *lp) int i, status = 0; for (i = 0; i < ARRAY_SIZE(enet_det); i++) { - if (!de4x5_strncmp((char *)&lp->srom, (char *)&enet_det[i], 3) && - !de4x5_strncmp((char *)&lp->srom+0x10, (char *)&enet_det[i], 3)) { + if (!memcmp(&lp->srom, &enet_det[i], 3) && + !memcmp((char *)&lp->srom+0x10, &enet_det[i], 3)) { if (i == 0) { status = SMC; } else if (i == 1) { @@ -4125,18 +4123,6 @@ de4x5_bad_srom(struct de4x5_private *lp) return status; } -static int -de4x5_strncmp(char *a, char *b, int n) -{ - int ret=0; - - for (;n && !ret; n--) { - ret = *a++ - *b++; - } - - return ret; -} - static void srom_repair(struct net_device *dev, int card) {