Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp875841pxj; Fri, 14 May 2021 19:26:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwymsU4NnxAuMdDWtJWuyO9wIqAlJ2Wi4KpCz4ixNXRsQ336L8Siwk5I6ni5F2fy6DY3+ic X-Received: by 2002:a05:6402:2712:: with SMTP id y18mr61798286edd.41.1621045594087; Fri, 14 May 2021 19:26:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621045594; cv=none; d=google.com; s=arc-20160816; b=Q8SBMFc6AZe1LY3/sGdvDgOFS2nD/Pnmnv3eKRyJSRlGHW7zTth1VCbg47I9JK5VgL y6yfriHmbRolZzieV1RcvgLhtwHsEKmRLS3rgPdRQJegVRxiUTXh/WDJfGyLMf0XnGr4 rr3vHVhKuZGfGx10lZMvDBm2ez8+Pgg1PfYJwHUbbbNGH256vznd56yoJ7IUSc74+tB3 IYlVpI+TvjYVlhOV4SUcqpwHRnUSXmos7k0g/nYcKMIJuu7b9Mvqaur6ov7URPwecOuE VuX9WGqRECNbSwDOcnKmSJlyzuASQpvRay8va6oMkSNTVPakLD4KcsFxV1rbyy8NoId9 WsrA== 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 :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=CnETe2qI9F6c5Qm7ij/9B8nKpkO2SKZ0pVueHpeiL8E=; b=F/B/PbvfcygDjspqwuJRVz5OTJa31KVFCNmpdbQv4uEcP5UnSohOA7KV6iJCPphyHn 5TWctWKQ2jnX+KFwdmfzoI4G5grc/z4Rwzu2hIPjCxDfrNXT5VqXHNjCotWsi6WPdsue xwntYSfGv2WDXAfc2hwWjQIsEDjWOcGWwzhgRhICVe8ZPFAG/YF2MF6UB8yzaUGRY0Dg nQqnqGOv9vm5i0iWRoPTnDAO4xPGVIopFI/sNrLT5p9yg3pqzQ26SM7WtPJMBBgP29AX iwV1P2LYyS+p6QkFUO62PbgML61lvb4KKLAYA0ocQBXK06bW9BWBrb0fcxjBHZ2Xu/TE anzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NasdIl1l; 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 e6si8612687edz.576.2021.05.14.19.26.11; Fri, 14 May 2021 19:26:34 -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=k20201202 header.b=NasdIl1l; 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 S230142AbhENVYH (ORCPT + 99 others); Fri, 14 May 2021 17:24:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:52740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229504AbhENVYG (ORCPT ); Fri, 14 May 2021 17:24:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9FA43613BB; Fri, 14 May 2021 21:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621027375; bh=0B3vRzqZ6K4f9UvjfOOfzoQhIiCFoDeVGmsMqIbrkJw=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=NasdIl1l9tT5rUPuIDMyvvfYYcKOQmtML694FQkUFSaJdrwROCeX4kVrVqB3kqQl8 e0yT5W8xzCBDInwJ8ssRxXTEX/YeuRdoq1VsNFEiFhRNENVDq5wydwdp8yaTWnS0XB rB1obsszE0sc052b0QoSwIe3ZaxG9Fr76AR10Kee+CyPISsvO2T2hKx60RMHWfP3AC FY4QYEtPhX0ImNwN/sWfQNvJ4i40gL8N/4O+OYYC2IFKNuAqvuW8owkfXT2CqTqC1q z2rjO4OA31GY6J8C7J9fO3kobVqN/TQu+67bY+3fNPB8nRh3p3sfpWvlxglaSWnuHs gwZvKaeJbhz5g== Subject: Re: [PATCH] [v2] platform/surface: aggregator: avoid clang -Wconstant-conversion warning To: Arnd Bergmann , Maximilian Luz , Hans de Goede Cc: Arnd Bergmann , platform-driver-x86@vger.kernel.org, Nick Desaulniers , linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com References: <20210514200453.1542978-1-arnd@kernel.org> From: Nathan Chancellor Message-ID: <057b5568-c4b8-820c-3dd7-2200f61a4d58@kernel.org> Date: Fri, 14 May 2021 14:22:53 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210514200453.1542978-1-arnd@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/14/2021 1:04 PM, Arnd Bergmann wrote: > From: Arnd Bergmann > > Clang complains about the assignment of SSAM_ANY_IID to > ssam_device_uid->instance: > > drivers/platform/surface/surface_aggregator_registry.c:478:25: error: implicit conversion from 'int' to '__u8' (aka 'unsigned char') changes value from 65535 to 255 [-Werror,-Wconstant-conversion] > { SSAM_VDEV(HUB, 0x02, SSAM_ANY_IID, 0x00) }, > ~ ^~~~~~~~~~~~ > include/linux/surface_aggregator/device.h:71:23: note: expanded from macro 'SSAM_ANY_IID' > #define SSAM_ANY_IID 0xffff > ^~~~~~ > include/linux/surface_aggregator/device.h:126:63: note: expanded from macro 'SSAM_VDEV' > SSAM_DEVICE(SSAM_DOMAIN_VIRTUAL, SSAM_VIRTUAL_TC_##cat, tid, iid, fun) > ^~~ > include/linux/surface_aggregator/device.h:102:41: note: expanded from macro 'SSAM_DEVICE' > .instance = ((iid) != SSAM_ANY_IID) ? (iid) : 0, \ > ^~~ > > The assignment doesn't actually happen, but clang checks the type limits > before checking whether this assignment is reached. Replace the ?: > operator with a __builtin_choose_expr() invocation that avoids the > warning for the untaken part. > > Fixes: eb0e90a82098 ("platform/surface: aggregator: Add dedicated bus and device type") > Cc: platform-driver-x86@vger.kernel.org > Signed-off-by: Arnd Bergmann Reviewed-by: Nathan Chancellor > --- > v2: use __builtin_choose_expr() instead of a cast to shut up the warning > --- > include/linux/surface_aggregator/device.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/include/linux/surface_aggregator/device.h b/include/linux/surface_aggregator/device.h > index 4441ad667c3f..6ff9c58b3e17 100644 > --- a/include/linux/surface_aggregator/device.h > +++ b/include/linux/surface_aggregator/device.h > @@ -98,9 +98,9 @@ struct ssam_device_uid { > | (((fun) != SSAM_ANY_FUN) ? SSAM_MATCH_FUNCTION : 0), \ > .domain = d, \ > .category = cat, \ > - .target = ((tid) != SSAM_ANY_TID) ? (tid) : 0, \ > - .instance = ((iid) != SSAM_ANY_IID) ? (iid) : 0, \ > - .function = ((fun) != SSAM_ANY_FUN) ? (fun) : 0 \ > + .target = __builtin_choose_expr((tid) != SSAM_ANY_TID, (tid), 0), \ > + .instance = __builtin_choose_expr((iid) != SSAM_ANY_IID, (iid), 0), \ > + .function = __builtin_choose_expr((fun) != SSAM_ANY_FUN, (fun), 0) > > /** > * SSAM_VDEV() - Initialize a &struct ssam_device_id as virtual device with >