Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp1192626ybh; Sat, 3 Aug 2019 20:15:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqw/wYgDuaP40e2LPDfBXJ48SCeO/BLIH5PygI3Pva5E91eUUXcCLANpSYnUH3Que23xREaD X-Received: by 2002:a62:642:: with SMTP id 63mr67493657pfg.257.1564888515430; Sat, 03 Aug 2019 20:15:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564888515; cv=none; d=google.com; s=arc-20160816; b=LBS2X7TFEIVQh+wlZwpf5dsXvb/pVW42kXgrHfMumSQn0wu3zf/gSqAsrS5Lk3bnXq 9P9Fompr/xlfTd9EF/S095IWWDEUVlxo6v4i6haJveU6VQYr6HMB0eJt4+S1F8HFeMwX osHC9t0Qb9I9OPx4E9O8Bl4a3Qj4iMWAmjyp1IHdhk6O1zXG/5+jIZj8BWU1ZmL6w516 DGAfjYsEdw93oD5FeJ5mJ+gkLIyCA5/8WDE991LJfnWoDZ62e5nAR4CHs+yIQxDnTY5V Yeyt3/antcdXgX9KXp/vNYnFSoem3lV05hqmiTpi/HY0Zv+i460Q2oM2L91F+gUX5nQe 7p8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date; bh=CqMZwZf8X9KBvfJdWHJZmsRVk7cV8YeZRAx64gu7/r8=; b=Y+gnh4dx3ifYdGi3nGpBNszcB/UbW9g7TIA+v2ZcAAIwmrhdFIB6lyUAeM93eHp0jo fl9EgDZ+VMHmGInAfDC4DgHr2n8BFJ6wRy6zaX0r2j9XX5BGq18M1DEZcvPkUaL1PPC/ 02epGgrC00CD7219Q11hcuy+2TT05h90K1z50n95zW2cC3+GLLxnSP6WcKm3KV40e9s7 jKbtp8LIEDkjuXijlhX2cQ6QXrIG2DBLJW1jG7EEHxKvHEUY4mSVMF12B7caG2PKdP66 tPjRze/LrdLBlmUbTesEwkQvxhG6zX+NtOtOTvGYrPgXK9pjKXTFJTGv02ciqup5Hy06 wmDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b7si43073076pfp.4.2019.08.03.20.15.00; Sat, 03 Aug 2019 20:15:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437317AbfHBXFH (ORCPT + 99 others); Fri, 2 Aug 2019 19:05:07 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:23218 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730376AbfHBXFH (ORCPT ); Fri, 2 Aug 2019 19:05:07 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x72Mv1EP022517; Fri, 2 Aug 2019 19:05:02 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 2u4vbvm5qm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 02 Aug 2019 19:05:02 -0400 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.27/8.16.0.27) with SMTP id x72Mv3Z6022785; Fri, 2 Aug 2019 19:05:02 -0400 Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0a-001b2d01.pphosted.com with ESMTP id 2u4vbvm5pr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 02 Aug 2019 19:05:01 -0400 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id x72MtJ5R004813; Fri, 2 Aug 2019 23:05:00 GMT Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by ppma04dal.us.ibm.com with ESMTP id 2u0e87hgdu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 02 Aug 2019 23:05:00 +0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x72N4xTO53150118 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 2 Aug 2019 23:04:59 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B780FB206B; Fri, 2 Aug 2019 23:04:59 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9AD1CB2068; Fri, 2 Aug 2019 23:04:59 +0000 (GMT) Received: from paulmck-ThinkPad-W541 (unknown [9.70.82.154]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 2 Aug 2019 23:04:59 +0000 (GMT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id 96AA116C9A3A; Fri, 2 Aug 2019 16:05:01 -0700 (PDT) Date: Fri, 2 Aug 2019 16:05:01 -0700 From: "Paul E. McKenney" To: Chuhong Yuan Cc: Davidlohr Bueso , Josh Triplett , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 03/10] locking/locktorture: Replace strncmp with str_has_prefix Message-ID: <20190802230501.GS28441@linux.ibm.com> Reply-To: paulmck@linux.ibm.com References: <20190802014656.8789-1-hslester96@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190802014656.8789-1-hslester96@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-08-02_10:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908020239 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 02, 2019 at 09:46:56AM +0800, Chuhong Yuan wrote: > strncmp(str, const, len) is error-prone because len > is easy to have typo. > The example is the hard-coded len has counting error > or sizeof(const) forgets - 1. > So we prefer using newly introduced str_has_prefix > to substitute such strncmp. > > Signed-off-by: Chuhong Yuan Queued, thank you! I updated the commit log as follows. Please let me know if I messed anything up. Thanx, Paul ------------------------------------------------------------------------ commit e2be525371b2f6790f6c1ab712c3d273fb1f2bea Author: Chuhong Yuan Date: Fri Aug 2 09:46:56 2019 +0800 locktorture: Replace strncmp() with str_has_prefix() The strncmp() function is error-prone because it is easy to get the length wrong, especially if the string is subject to change, especially given the need to account for the terminating nul byte. This commit therefore substitutes the newly introduced str_has_prefix(), which does not require a separately specified length. Signed-off-by: Chuhong Yuan Signed-off-by: Paul E. McKenney diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index c513031cd7e3..8dd900247205 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c @@ -889,16 +889,16 @@ static int __init lock_torture_init(void) cxt.nrealwriters_stress = 2 * num_online_cpus(); #ifdef CONFIG_DEBUG_MUTEXES - if (strncmp(torture_type, "mutex", 5) == 0) + if (str_has_prefix(torture_type, "mutex")) cxt.debug_lock = true; #endif #ifdef CONFIG_DEBUG_RT_MUTEXES - if (strncmp(torture_type, "rtmutex", 7) == 0) + if (str_has_prefix(torture_type, "rtmutex")) cxt.debug_lock = true; #endif #ifdef CONFIG_DEBUG_SPINLOCK - if ((strncmp(torture_type, "spin", 4) == 0) || - (strncmp(torture_type, "rw_lock", 7) == 0)) + if ((str_has_prefix(torture_type, "spin")) || + (str_has_prefix(torture_type, "rw_lock"))) cxt.debug_lock = true; #endif