Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1241751pxy; Fri, 23 Apr 2021 03:47:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwE7Tx1xdTBanDYjwmZ9u3Nx2dr0HUa94SokaKcVXex3mMS3wdjC11pSMthbYeW03fSaPel X-Received: by 2002:a17:906:3111:: with SMTP id 17mr3404356ejx.403.1619174850860; Fri, 23 Apr 2021 03:47:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619174850; cv=none; d=google.com; s=arc-20160816; b=W6vXlhtPtC3ohl5q526NHZtfU54ZfjHEP58xg59ZjpoV6VZqnBsQjWMykktg/ks83b KbbcxAerY6/RTjwt6Xgz7puKn2Y1+alnncxheFiviL8MTqSZF4yI69tKt/CsuaOnwhZO e3f3R6XL4f/3xUv2HwoBSsk3mNzEQBYHSFIlLS7n0qGkP81IL9bigCV+UZDS4inCDqSf CyFxDHH3563GSIY0mT5DHFdgn9DZGNHSyjw82rmsOS0rcPtpjHPnM/ArzJy18DFOYxrh nc92OI2jHIEn61yDnTw1WvBQfY7jUfHAENo4uFrhqoDYILS/KLcBUQo/1MGFhrHEqk2C GYfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from:dkim-signature; bh=TgFjxtYsOVaP6v4PMZp8irtY/yFk5woDCqAeiCFqABA=; b=xte+wcs0Q2KiAe4iC2HvQlevZtPYHrfcGpwE57nG8AB5+NsxxrOZFBjiI3wRy6RE8f /FNsAgrwmbK+lX6sB7/WP+Jouca1es1xSx4C0L5PMDysz2IYPUebd79BGeV0NiVheUIZ r2qubiuWp12fpNIGScuSgnph2LR9goEw4QGf0906ElsPjLYXyJrS9PKr2hhEF8rIGp1E KswMXMvWOwYQl/qgXv5Q1fu9ypkQXMvIxTjwcdUFVu60mlbBflP+SCvUJikidA6qXePK sOCT6vCcqNfTiHFa/KYWyiOfHnwga/yyLX6/TVoLgoluibIhwqKX8K7uAgjVB5H9hPcU V4hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dPWtMidH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ca6si4607941edb.84.2021.04.23.03.47.06; Fri, 23 Apr 2021 03:47:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dPWtMidH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229965AbhDWKqV (ORCPT + 99 others); Fri, 23 Apr 2021 06:46:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229794AbhDWKqU (ORCPT ); Fri, 23 Apr 2021 06:46:20 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80C19C061574; Fri, 23 Apr 2021 03:45:44 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id 4so16970043lfp.11; Fri, 23 Apr 2021 03:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=TgFjxtYsOVaP6v4PMZp8irtY/yFk5woDCqAeiCFqABA=; b=dPWtMidHtJu/eQ7X+GMrm8eY6cIAu28zOaBEA0d3WhtJ630XTxz/F1si9qzLMJHyG/ hWZjePMhtoigzpcf55ecqAtJmDbEQUIGFZm4CZYbpRJvR6ehddDWWL9cvB7Y2osTZyVs 1d3GIe/jyMetbl3liuB/IDuGoHaaM1ncGwjQEED08omLCh0S9wA785smoM5hmFfON8jq kM/Dhaqq5HJFosb4yvo4F7pOAtlz8ZwEjW94C5a2IYyOAdoB9N8jprhABxW8X2mVl2lg HJc0/A5nX1i+7MWdHiPNth6Nohuk1csOl/wAD1XaqIPxaLYpp7m+aKemnGq+Mdruix67 rGbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=TgFjxtYsOVaP6v4PMZp8irtY/yFk5woDCqAeiCFqABA=; b=NnkIfdifIn/GeG8fw5mRJDj7B4c6WfjUA74kxjkj8AS8/iiN2zeXtfgxIWf60oM+IS Im2FfJ/mo7Mid1m3GMyeE3XqY4nAmiEo8y2C3LX7CPb9OELs1VyXYe7dTajHssLqJMh3 /ZxEtVXHZXnjJV98VBcQEwO07fkJQYD4wD5X3kc4MXht4vcUp9MOTiMF+J8tkfLOtRZ4 oGXqazJa+zy1KB9nMnOmqHgTzJ+2s/58Hx+wJUydtZhqGm2dFNNQwLFbHgUWWVo8y2xr t6knmknwxtZApYi7m2+DD7QK5mbbiRgnDL/IcjE8HkmL705FLmd6xbvlrkpBccias5CE bjpw== X-Gm-Message-State: AOAM531bhQ6AX7rQFrFgSTNojnvUS5kpLbA+0nxbZ4GWnFsA0sZci2z5 40swAQREoyyo+L5InVyi4HnGgBLF/6A= X-Received: by 2002:ac2:5682:: with SMTP id 2mr2287134lfr.524.1619174742625; Fri, 23 Apr 2021 03:45:42 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id y8sm514938lfe.259.2021.04.23.03.45.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Apr 2021 03:45:41 -0700 (PDT) From: Sergey Organov To: David Laight Cc: 'Dan Carpenter' , Joel Stanley , Andrew Jeffery , "Chia-Wei, Wang" , Jae Hyun Yoo , "John Wang" , Brad Bishop , Patrick Venture , "Benjamin Fair" , Greg Kroah-Hartman , Robert Lippert , "linux-aspeed@lists.ozlabs.org" , "linux-kernel@vger.kernel.org" , "kernel-janitors@vger.kernel.org" Subject: Re: [PATCH] soc: aspeed: fix a ternary sign expansion bug References: <59596244622c4a15ac8cc0747332d0be@AcuMS.aculab.com> Date: Fri, 23 Apr 2021 13:45:40 +0300 In-Reply-To: <59596244622c4a15ac8cc0747332d0be@AcuMS.aculab.com> (David Laight's message of "Thu, 22 Apr 2021 16:21:40 +0000") Message-ID: <877dktuvmz.fsf@osv.gnss.ru> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org David Laight writes: > From: Dan Carpenter >> Sent: 22 April 2021 10:12 >> >> The intent here was to return negative error codes but it actually >> returns positive values. The problem is that type promotion with >> ternary operations is quite complicated. >> >> "ret" is an int. "copied" is a u32. And the snoop_file_read() function >> returns long. What happens is that "ret" is cast to u32 and becomes >> positive then it's cast to long and it's still positive. >> >> Fix this by removing the ternary so that "ret" is type promoted directly >> to long. >> >> Fixes: 3772e5da4454 ("drivers/misc: Aspeed LPC snoop output using misc chardev") >> Signed-off-by: Dan Carpenter >> --- >> drivers/soc/aspeed/aspeed-lpc-snoop.c | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/soc/aspeed/aspeed-lpc-snoop.c b/drivers/soc/aspeed/aspeed-lpc-snoop.c >> index 210455efb321..eceeaf8dfbeb 100644 >> --- a/drivers/soc/aspeed/aspeed-lpc-snoop.c >> +++ b/drivers/soc/aspeed/aspeed-lpc-snoop.c >> @@ -94,8 +94,10 @@ static ssize_t snoop_file_read(struct file *file, char __user *buffer, >> return -EINTR; >> } >> ret = kfifo_to_user(&chan->fifo, buffer, count, &copied); >> + if (ret) >> + return ret; >> >> - return ret ? ret : copied; >> + return copied; > > I wonder if changing it to: > return ret ? ret + 0L : copied; > > Might make people think in the future and not convert it back > as an 'optimisation'. It rather made me think: "what the heck is going on here?!" Shouldn't it better be: return ret ? ret : (long)copied; or even: return ret ?: (long)copied; ? -- Sergey Organov