Received: by 2002:a05:6a10:144:0:0:0:0 with SMTP id 4csp34637pxw; Thu, 7 Apr 2022 23:44:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxF/zoTH0Y1cOQOD4xwz+fN2TosqStN+fOOTFqJ9uVo0Vz9wUVlDmiooess6s+35/MNMG2t X-Received: by 2002:a17:902:a981:b0:156:52b2:40d6 with SMTP id bh1-20020a170902a98100b0015652b240d6mr17968135plb.34.1649400265451; Thu, 07 Apr 2022 23:44:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649400265; cv=none; d=google.com; s=arc-20160816; b=MTnohbleQYXAuHjUa0Jm1cdxc6EcMiI462hhGcYZvgYKdt+gq/M8LJgv4NQGyJSumG EMY7d+jsDnjVviYoqy/u9OdyCngVDsAowx0U6D0g51PPSAKxHs2gpTshlbKf7C5FxGub tAvwAL4OHAkXpNZSAuI5N5QbQJfMEtR1/ctORGVXRoQLI5R/HEbJQYE0FurMe9rXYDK3 Y/jZ1yEVdVOR6ApAX200WmNiu2EkJfMdMEmjNth3sJjrfkH4COfhOPwGPQs37xyw7BdK QPcDbGb7Jt4ptfyyCVhX/F7ExnbUEwumhiQHGA6alIprZq7DaZvlGNSusicIIlb1TF5P jVwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=PLVZyES/2eblcHRf8JGLBDgTbBs4+6e4nn03zdfInFI=; b=S4Nt6wXXMXpbbWOZA4b5mpBfclKUqlodVSCkChALQGeOBG8hOkqKYWmWAhqm/1maCQ 8egO7v0AB612yiWcOShHKGcwD/5u71TRhbawuIcgvTwuaDg1O3OPcnRXq/qOsE3oIpch Ty2P2BBym1Y2Dik+Z9w6FwuEhIk05AcoIfwKDB4mQiGhBXIwsTTZoVEK9yd6I1pvYew1 y0/jZj/Tju39T5tfUWm92/gacq9QKmfLkxNr3O+Yke3uhVI4OV7yyUvbFeZg/TPVCpZq hNG30C6Xoyp18Afwm4MuwnHD6h3sDOnTzWCA87tBiy8hlDat++gejE/lVg45ztNFMJR/ Tuzg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id my18-20020a17090b4c9200b001bd14e030bcsi443381pjb.148.2022.04.07.23.44.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 23:44:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 10E7F37031; Thu, 7 Apr 2022 23:15:08 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230436AbiDHGRE (ORCPT + 99 others); Fri, 8 Apr 2022 02:17:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229773AbiDHGRD (ORCPT ); Fri, 8 Apr 2022 02:17:03 -0400 Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5A59BE39 for ; Thu, 7 Apr 2022 23:15:00 -0700 (PDT) Received: from omf05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 692B980C8C; Fri, 8 Apr 2022 06:14:59 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf05.hostedemail.com (Postfix) with ESMTPA id 9A66F2001A; Fri, 8 Apr 2022 06:14:52 +0000 (UTC) Message-ID: <34d0ad73f44ff4990f6bee49105ac49bb55352a5.camel@perches.com> Subject: Re: [PATCH v2 1/2] staging: rtl8192u: replace ternary statement with if and assignment From: Joe Perches To: Dan Carpenter , Julia Lawall Cc: Rebecca Mckeever , outreachy@lists.linux.dev, Greg Kroah-Hartman , linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Date: Thu, 07 Apr 2022 23:14:51 -0700 In-Reply-To: <20220408055732.GO3293@kadam> References: <36059ec66a2f3d58a8e339aa4f262772eabd3ef0.1649378587.git.remckee0@gmail.com> <20220408055732.GO3293@kadam> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.40.4-1ubuntu2 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspamout07 X-Rspamd-Queue-Id: 9A66F2001A X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Stat-Signature: u4og487og7ehspsp5guqhsgjtw76i9ch X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1+cZfbi4qHorwDzKAdQesA7qUgqDtKrODY= X-HE-Tag: 1649398492-439562 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2022-04-08 at 08:57 +0300, Dan Carpenter wrote: > On Fri, Apr 08, 2022 at 06:15:14AM +0200, Julia Lawall wrote: > > On Thu, 7 Apr 2022, Rebecca Mckeever wrote: > > > > > Replace ternary statement with an if statement followed by an assignment > > > to increase readability and make error handling more obvious. > > > Found with minmax coccinelle script. [] > > > diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c [] > > > @@ -470,7 +470,9 @@ int ieee80211_wx_get_encode(struct ieee80211_device *ieee, > > > return 0; > > > } > > > len = crypt->ops->get_key(keybuf, SCM_KEY_LEN, NULL, crypt->priv); > > > - erq->length = (len >= 0 ? len : 0); > > > + if (len < 0) > > > + len = 0; > > > + erq->length = len; > > > > Maybe you could use max here? > > Initially Rebecca did use max() but I NAKed it. It's really not less > readable. Better to handle the error explicitly. Keep the error path > indented two tabs. Separate from the success path. A comment would be useful as it's not obvious it's an 'error' path. One has to read all 3 get_key functions to determine that.