Received: by 2002:a05:6a10:144:0:0:0:0 with SMTP id 4csp52961pxw; Fri, 8 Apr 2022 00:22:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUAtTF6AcKrAdxzqGgrEtesk/aQufUE792ZMcyF/SL74sYdTIHCUR9KhfUZhd/A69njm/g X-Received: by 2002:a17:902:c948:b0:156:c07d:8222 with SMTP id i8-20020a170902c94800b00156c07d8222mr18046705pla.30.1649402537651; Fri, 08 Apr 2022 00:22:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649402537; cv=none; d=google.com; s=arc-20160816; b=rNisFhkiTzQtEN783BlqoUKr00nFyoI0JjMydQzYb/1JSKmbO4q2kJOcLxrOOuYXuj hCi6Je79bSZ3DNbno2kk6slSK6HryJXZa8iHYqbMSB9LbUSCQSq82I1TLWnH7WfTKXvF q0ub3EBFL/IBUEIKQ5UY0Ot0RKGWYTmSZl8V3DaWB81pqdZm8JJWUDosmTMz3p/kNmBX JwDExHDd8ATgYHn3HDCs2LHQjgV1nHH4X10WM1+5HWveuh8U2zZZBH6oj/LSfYIb/zoE 7t+AZ9JQB0rHyHJKaoSygBH/buF6VkcdkLKoAtsrG1z2dEI2QcwVeJS2ltDWyIuG73Gq raVw== 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=HCd6eARVhWdApljFmD5ImiouIZE6ar0X4YX6vYh9Aqg=; b=mHQIrgVPasGc91aLdzYUEZ4wbr4djl/4S4NOg5S5ayUGZPfSpHzepi1nr09p+ZeZX4 u5LZSm1HbDKOeS6m+zllEfrJ+X6P66itZzSFBLYLvX14zSlCaE+AhFgQ+48J8n41PILk PomgaMKl+3pkDx9t4iKSg4D1IxxdbUYJkW/+B55h4g5KxTqi/eAhuKcwr37OG9aFe+zC FuI7xbLWDfBZGYQ6Idac+D7YqoxJNk5BwSUVFVQuiqf0KNYHHm3u24TEMUDiRTqbenYK +w96q/hUBfbehY0PMJIOxP+ETbWF1ZwRUSZVn9kC+6MMndOjbvb02V2NS/k7fybYhtus TD1w== 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:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t125-20020a635f83000000b003863b74af82si551810pgb.393.2022.04.08.00.22.05; Fri, 08 Apr 2022 00:22:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229793AbiDHHVd (ORCPT + 99 others); Fri, 8 Apr 2022 03:21:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229901AbiDHHVY (ORCPT ); Fri, 8 Apr 2022 03:21:24 -0400 Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECA4226D10B for ; Fri, 8 Apr 2022 00:19:09 -0700 (PDT) Received: from omf15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 7A4A860C9E; Fri, 8 Apr 2022 07:19:08 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf15.hostedemail.com (Postfix) with ESMTPA id DC18D1C; Fri, 8 Apr 2022 07:19:01 +0000 (UTC) Message-ID: Subject: Re: [PATCH v2 1/2] staging: rtl8192u: replace ternary statement with if and assignment From: Joe Perches To: Dan Carpenter Cc: Julia Lawall , Rebecca Mckeever , outreachy@lists.linux.dev, Greg Kroah-Hartman , linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Date: Fri, 08 Apr 2022 00:19:01 -0700 In-Reply-To: <20220408063133.GP12805@kadam> References: <36059ec66a2f3d58a8e339aa4f262772eabd3ef0.1649378587.git.remckee0@gmail.com> <20220408055732.GO3293@kadam> <34d0ad73f44ff4990f6bee49105ac49bb55352a5.camel@perches.com> <20220408063133.GP12805@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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Stat-Signature: z9ba1f5jjc67q58cs4yz37pqbsf4e9xk X-Rspamd-Server: rspamout04 X-Rspamd-Queue-Id: DC18D1C X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1+QikhRhVzwWv/z8uStoYQzqEakv0U9mx8= X-HE-Tag: 1649402341-483837 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 09:31 +0300, Dan Carpenter wrote: > On Thu, Apr 07, 2022 at 11:14:51PM -0700, Joe Perches wrote: > > 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. > > > > I'm so confused. Negative error codes are the common case in the > kernel. We don't need to comment it. If it was an error, it would handle it as an error not set len to 0 and continue. That's why IMO a comment is useful.