From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0ADF3C433B4 for ; Thu, 22 Apr 2021 09:26:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD43B613FA for ; Thu, 22 Apr 2021 09:26:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235621AbhDVJ1S (ORCPT ); Thu, 22 Apr 2021 05:27:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230341AbhDVJ1R (ORCPT ); Thu, 22 Apr 2021 05:27:17 -0400 Received: from zeniv-ca.linux.org.uk (zeniv-ca.linux.org.uk [IPv6:2607:5300:60:148a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56CE2C06174A; Thu, 22 Apr 2021 02:26:43 -0700 (PDT) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94 #2 (Red Hat Linux)) id 1lZVbP-007H9U-Iu; Thu, 22 Apr 2021 09:26:27 +0000 Date: Thu, 22 Apr 2021 09:26:27 +0000 From: Al Viro To: Dan Carpenter Cc: 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 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 22, 2021 at 09:24:59AM +0000, Al Viro wrote: > On Thu, Apr 22, 2021 at 12:11:44PM +0300, Dan Carpenter wrote: > > 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. > > Hmm... Let's grep for kfifo_to_user() - smells like a possible recurring bug... > Yup - > > samples/kfifo/bytestream-example.c:138: ret = kfifo_to_user(&test, buf, count, &copied); > samples/kfifo/inttype-example.c:131: ret = kfifo_to_user(&test, buf, count, &copied); > samples/kfifo/record-example.c:145: ret = kfifo_to_user(&test, buf, count, &copied); > > All three are exactly like that one. Nevermind, you've already caught and posted that bunch. Sorry for noise...