Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp780818ybj; Thu, 7 May 2020 07:31:05 -0700 (PDT) X-Google-Smtp-Source: APiQypJQfTCsI2X0t1h8jM2zSWCCYCx4WwsnFpyixsPTAIYEM+qmwQLy205NgDSFWS5LMyZEWCic X-Received: by 2002:a05:6402:206f:: with SMTP id bd15mr12553408edb.24.1588861865290; Thu, 07 May 2020 07:31:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588861865; cv=none; d=google.com; s=arc-20160816; b=NlErll9503nVAtMnvcwA2H2SQnNjLrJKBYbMZk9gK0dvLcvJesLDm009PJnMw8egJ6 rv8Z/4xyK5Mje/VqxCdrkm0dOKtjyvEBKM/qMp6o8AprUoKmb0IgRiu8qBT8wDIA+2/O Ng2hLWJm2Pp3X3SyIkENAFZu7jowgmKIVbU5cbE70LCVoD7Pk7A8kN4ttrOF0CA47qhZ 74+3NOfaKqoADaMfgtF7rzARreShu9S7uZ5R/82cGNnoL1mESDaOkO6UR74x+cQN06T1 Nn7HyTS52BKeEIWuvFIT98pvbxsE7Mgda9np0mRks/QKum5UaRVvPWm9pjm4OrCOJZK0 Hayw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PeivNfgxO23PC5bQlbii75u0KIlSKL95MGHTh9k5SBE=; b=IDB5ukVdPHGv0pfOZttPO7OU2kaU7HNv8i1QDUvklkTQADKqGG/zcfknC+qqLtiBCI T8dWM4VW7IP7Lcp3EZ8nAOe92EaoO7ISBriek4HCVlL0B0MB+YA8anygP8IYtevZK9qc NjpqpIiPWrMD8BKwQAWXule9sObdTlNyhNJ8uTZvd+l50+rv7X2bjykg2Hwm5xajIk3L biZsPPXPmNrBAzLKVvgBmUgy/Wl9vVpNzONYaTs56XxHrtT1/G4ZKHZ9icGMUpVr7FxG z9cY5ra9MNuclAam41MR4ed3Ycy1nCJgO7Q+cyQdW0DsORpRPeNuV7j9M0R91eJrKa0R C6zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="UnXO/kvK"; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h21si3143631ejc.152.2020.05.07.07.30.31; Thu, 07 May 2020 07:31:05 -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=@kernel.org header.s=default header.b="UnXO/kvK"; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728081AbgEGO2W (ORCPT + 99 others); Thu, 7 May 2020 10:28:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:54774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728042AbgEGO2S (ORCPT ); Thu, 7 May 2020 10:28:18 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 140E120B1F; Thu, 7 May 2020 14:28:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588861697; bh=KQII8MNasLBxLsIQPhEplSuFHAqYHyRYa/rGvyPtqCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UnXO/kvKAhpvG5iRPrO07SPmqWj/dqlAmFRnV44HBN9cjcVm6pVvIoM8vlKf+UtBK 9sNFKYIDlmehhnmmTxuOVRYeAQNPs7MIaC77wG5idgSCTuLHOVy8H04txwNMo0KChR OcWD7cWEPqeDW4Vurxvn6PNzvnQUb60YTfvmltdI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Arnd Bergmann , Takashi Iwai , Sasha Levin , alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 5.6 40/50] ALSA: opti9xx: shut up gcc-10 range warning Date: Thu, 7 May 2020 10:27:16 -0400 Message-Id: <20200507142726.25751-40-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200507142726.25751-1-sashal@kernel.org> References: <20200507142726.25751-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 [ Upstream commit 5ce00760a84848d008554c693ceb6286f4d9c509 ] 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 Link: https://lore.kernel.org/r/20200429190216.85919-1-arnd@arndb.de Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- 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 e764816a8f7a1..b039429e68717 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)); +} /* * Proc Interface diff --git a/sound/isa/opti9xx/opti92x-ad1848.c b/sound/isa/opti9xx/opti92x-ad1848.c index d06b29693c85f..0e6d20e491585 100644 --- a/sound/isa/opti9xx/opti92x-ad1848.c +++ b/sound/isa/opti9xx/opti92x-ad1848.c @@ -317,10 +317,13 @@ static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg, } -#define snd_opti9xx_write_mask(chip, reg, value, mask) \ - snd_opti9xx_write(chip, reg, \ - (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask))) +static inline void snd_opti9xx_write_mask(struct snd_opti9xx *chip, + unsigned char reg, unsigned char value, unsigned char mask) +{ + unsigned char oldval = snd_opti9xx_read(chip, reg); + snd_opti9xx_write(chip, reg, (oldval & ~mask) | (value & mask)); +} static int snd_opti9xx_configure(struct snd_opti9xx *chip, long port, -- 2.20.1