Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1558910ybz; Thu, 30 Apr 2020 01:17:55 -0700 (PDT) X-Google-Smtp-Source: APiQypL4OQLkYreBhTNDzH9f1auyBmHL9/MC8x0eh3KnjV4XVOdGswNog49tSrGVTVgWZDR01I9q X-Received: by 2002:a17:906:f90d:: with SMTP id lc13mr1501150ejb.367.1588234675343; Thu, 30 Apr 2020 01:17:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588234675; cv=none; d=google.com; s=arc-20160816; b=blkcSuHOakKcSp7wHknkYbedXdsQCtGcg+wvaaIvkQLkxQ1LQrJrq4Y2iJ4mTzso18 3qXLG6FTgSwLa5EWLM/NxZluI6Iw4rY+aT/zrMgiG/eURtmr85sD+0vZmoDgMCh/to/q mt1FGaP/ircJiNMbKyYAUAz15L3tIuATs0XLbJyDlUV5gJvF4pr4jyJ+2y02Rm6sSjBm q0X/YZtBMZE3KmJNRanv6WJyRzeUPNp2K7i3gpWgCJg6CI1sKQtYyk+mkb7JrGSEJVjP GI8564K9yWnWl2KSaKvc31P0bVKbjmQ8KUY0qO9y1n2iNKxHVhPoBPvPYjdEpn/UyeQA HeRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=hYnl7o/Su4kqUasZh895aiobunBhfnOz8jSJsb0J8+c=; b=EMlme1/I0F+xJGuvQ9XdIWt4CGjCNv9F+DcwTZt13WdRJEg2ENJn+RIuYfzUcuZ7Jb XNumY4juEJ1b1Un628qFuGX4Jg5ZP+ECTJPIpdLY71Hsqq2hNzrrV6sSZOSKiv7DeumB i2H8PR5lI/W1uyP1wAHBQ8Ge+1wLD9Fk6P1fCDNKi2cbCIvV58s4m15Zp0/LLek5zcwh 9ccYyxDZmMD1lQRnVZFtFmRg62IzfrjoYWwGdCL9B8zOBgVIBPHBBZ5XNLeDXroIxA6J r7eYq3jUOslPaMQxGUP+TEcqDkNWVF+ak7cl9dFFS6kWoMjrwWgsd8ch63ndBUEIu5Aa B+bQ== 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 u3si5221166edp.525.2020.04.30.01.17.31; Thu, 30 Apr 2020 01:17:55 -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 S1726685AbgD3IPH convert rfc822-to-8bit (ORCPT + 99 others); Thu, 30 Apr 2020 04:15:07 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([146.101.78.151]:23412 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726127AbgD3IPH (ORCPT ); Thu, 30 Apr 2020 04:15:07 -0400 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-163-g0_seeJgO5ihcWbcW0LISw-1; Thu, 30 Apr 2020 09:15:03 +0100 X-MC-Unique: g0_seeJgO5ihcWbcW0LISw-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Thu, 30 Apr 2020 09:15:02 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Thu, 30 Apr 2020 09:15:02 +0100 From: David Laight To: 'Arnd Bergmann' , Jaroslav Kysela , "Takashi Iwai" CC: Takashi Iwai , "alsa-devel@alsa-project.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH] ALSA: opti9xx: shut up gcc-10 range warning Thread-Topic: [PATCH] ALSA: opti9xx: shut up gcc-10 range warning Thread-Index: AQHWHljP0SPhFOMubESmHZ4J5JyFcqiRUaDQ Date: Thu, 30 Apr 2020 08:15:02 +0000 Message-ID: References: <20200429190216.85919-1-arnd@arndb.de> In-Reply-To: <20200429190216.85919-1-arnd@arndb.de> Accept-Language: en-GB, en-US Content-Language: 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann > Sent: 29 April 2020 20:02 > gcc-10 points out a few instances of suspicious integer arithmetic > leading to value truncation: > > sound/isa/opti9xx/opti92x-ad1848.c: In function 'snd_opti9xx_configure': > sound/isa/opti9xx/opti92x-ad1848.c:322:43: error: overflow in conversion from 'int' to 'unsigned char' > changes value from '(int)snd_opti9xx_read(chip, 3) & -256 | 240' to '240' [-Werror=overflow] > 322 | (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask))) > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~ > sound/isa/opti9xx/opti92x-ad1848.c:351:3: note: in expansion of macro 'snd_opti9xx_write_mask' > 351 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff); > | ^~~~~~~~~~~~~~~~~~~~~~ > sound/isa/opti9xx/miro.c: In function 'snd_miro_configure': > sound/isa/opti9xx/miro.c:873:40: error: overflow in conversion from 'int' to 'unsigned char' changes > value from '(int)snd_miro_read(chip, 3) & -256 | 240' to '240' [-Werror=overflow] > 873 | (snd_miro_read(chip, reg) & ~(mask)) | ((value) & (mask))) > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~ > sound/isa/opti9xx/miro.c:1010:3: note: in expansion of macro 'snd_miro_write_mask' > 1010 | snd_miro_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff); > | ^~~~~~~~~~~~~~~~~~~ > > These are all harmless here as only the low 8 bit are passed down > anyway. Change the macros to inline functions to make the code > more readable and also avoid the warning. > > Strictly speaking those functions also need locking to make the > read/write pair atomic, but it seems unlikely that anyone would > still run into that issue. > > Fixes: 1841f613fd2e ("[ALSA] Add snd-miro driver") > Signed-off-by: Arnd Bergmann > --- > sound/isa/opti9xx/miro.c | 9 ++++++--- > sound/isa/opti9xx/opti92x-ad1848.c | 9 ++++++--- > 2 files changed, 12 insertions(+), 6 deletions(-) > > diff --git a/sound/isa/opti9xx/miro.c b/sound/isa/opti9xx/miro.c > index e764816a8f7a..b039429e6871 100644 > --- a/sound/isa/opti9xx/miro.c > +++ b/sound/isa/opti9xx/miro.c > @@ -867,10 +867,13 @@ static void snd_miro_write(struct snd_miro *chip, unsigned char reg, > spin_unlock_irqrestore(&chip->lock, flags); > } > > +static inline void snd_miro_write_mask(struct snd_miro *chip, > + unsigned char reg, unsigned char value, unsigned char mask) > +{ > + unsigned char oldval = snd_miro_read(chip, reg); > > -#define snd_miro_write_mask(chip, reg, value, mask) \ > - snd_miro_write(chip, reg, \ > - (snd_miro_read(chip, reg) & ~(mask)) | ((value) & (mask))) > + snd_miro_write(chip, reg, (oldval & ~mask) | (value & mask)); > +} Isn't that likely to add additional masking with 0xff at the call sites? You will probably get better code if the arguments are 'unsigned int'. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)