Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1431778pxy; Fri, 23 Apr 2021 07:57:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyE9q4AaVvpLR6ZnjTiDm4cGWotoovsMuJu0PVqht1IwDqub06ql5cT9zkxicZ2hzwQuqm X-Received: by 2002:a63:4413:: with SMTP id r19mr4141660pga.75.1619189872060; Fri, 23 Apr 2021 07:57:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619189872; cv=none; d=google.com; s=arc-20160816; b=GAItUcYN7qkALGVsqZ1nn/eKGqEuJuxqKVF6cqZzZvZWtX0REs2wXFAe3K4ufpjX4r 16d1dBD5k9q8HAZPpQGiWEUSeQC14nYrYaWlxrM4f+PSMlDiV3+0G4Ig+TWe53RhrNdB NmvdCOXf1N7VTpRcQKu4Az0f5XY4a3b3UXYCocenMk8/6nY6VPFqp6HJaehAeO9WmNKG HB0o7f6TuIJrFttgPtTP3gqT7L35rXmDCi14nPqufS8vAId1p6iKzz71YlmcVuNlk4U8 zdC0yYtgfRyaHIV8JjGGjVJtPQaWRG8CGccKAvFjRvr3mYxcBqTo4CQQEVDZUdEH510G HUyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=vJZgl9JFN/1UTjz9gSmorWDNiWd2KawhglQGXEsSPGM=; b=JUBBSNJjgFoGxgow114PNVMr6+Wlu8wJwGmSbEIbNGqhzJVXDL6t8MivH4aLWJE2a+ QAyKpFQnyTxQF5NpDE8GanvKr16CkjKq/jCElp6fYTs0fDklzDgLsr4MiKgs+Wkq5+Rh yeFpxHRi2n3gcjS0H1clN/uHy8hAGI+TBcVTQOQYpptvWEC/sb9XSZ1GUb8ebcdB4FBK dlz0YGrWNK5eI4yturP2X2pKgaJJZPQxljfYG6wTDLMhnrhAdY4QRC1071T+iwOIvip9 vU4HcECXGwdlCjepQxhKZOYhXApIDeYl2grlF0wYh3vvpCeUShvCaat5MlzcPTsjnI1z Cq9Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 102si7235590plb.217.2021.04.23.07.57.39; Fri, 23 Apr 2021 07:57:52 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241013AbhDWO4M convert rfc822-to-8bit (ORCPT + 99 others); Fri, 23 Apr 2021 10:56:12 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.85.151]:43886 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237205AbhDWO4K (ORCPT ); Fri, 23 Apr 2021 10:56:10 -0400 Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-36-dOwhnU8nPbOR9TIB42nwTg-1; Fri, 23 Apr 2021 15:55:31 +0100 X-MC-Unique: dOwhnU8nPbOR9TIB42nwTg-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 23 Apr 2021 15:55:30 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.015; Fri, 23 Apr 2021 15:55:29 +0100 From: David Laight To: 'Sergey Organov' , Walter Harms 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: AW: [PATCH] soc: aspeed: fix a ternary sign expansion bug Thread-Topic: AW: [PATCH] soc: aspeed: fix a ternary sign expansion bug Thread-Index: AQHXOE6YUD1kHD3sxkSNy+8EQaJbFarCLf3Q Date: Fri, 23 Apr 2021 14:55:29 +0000 Message-ID: <635275613c384fe381df4ae4ac30f380@AcuMS.aculab.com> References: <59596244622c4a15ac8cc0747332d0be@AcuMS.aculab.com> <877dktuvmz.fsf@osv.gnss.ru> <265e2d3accc74c89b5bab22eadb43808@AcuMS.aculab.com> <878s59rrn0.fsf@osv.gnss.ru> In-Reply-To: <878s59rrn0.fsf@osv.gnss.ru> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sergey Organov > Sent: 23 April 2021 15:40 > > Walter Harms writes: > > > as indepentent observer, > > i would go for Dans solution: > > > > ret = kfifo_to_user(); > > /* if an error occurs just return */ > > if (ret) > > return ret; > > > > /* otherwise return the copied number of bytes */ > > > > return copied; > > > > there is no need for any deeper language knowledge, > > Yep, but this is not idiomatic C, so one looking at this code would > tend to convert it back to ternary, and the actual problem here is that > the type of 'copied' does not match the return type of the function. Actually changing the type of 'ret' to ssize_t is probably the safest change. That works until someone tries to optimise out 'ret' by doing: return kfifo_to_user(...) ?: count; Or rattle through and remove the 'pass by reference' 'count' parameter from kfifo_to_user() in favour of returning the value the callers want. I need to stop looking at this code :-) David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)