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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 07B63C001B0 for ; Mon, 14 Aug 2023 23:00:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References: List-Owner; bh=AhggF3FDsvzoGedgY6sa1qr9YJxGA92DNj/9UYtCjY8=; b=JkCtjPNc8YWAqe j2pB+DLzL8uwDguSW9kNC8seR0nRhXRnrJlxuhEynYy+aD7KJmRqINd0kAFWsuZXP0SJiOYtksoCg ojcSrDoL2bV1Xgm+s1qKj3/gohCsOsEMG+skxdKMSssxTYNRjOalomWZHy0ZyvtR4h6ZMlLQOF8LQ uw207OnnNlczkBX/JhQRj78oFEFeE3XMYAZUX7LGWDC0yVoh+w4Dq3oranIicrsdZjZbehUdxeJ2J IW9qryII8bd9AnfRNJmTjKO32InVW+TokWGjkt6kkJy2XIpEUqynzDixliDxJtGxKXt+OfB0jvwE6 PPrdU73AbSZ9eFq8zHNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qVgXn-000UnZ-1M; Mon, 14 Aug 2023 23:00:15 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qVgXk-000Un8-1u for linux-arm-kernel@lists.infradead.org; Mon, 14 Aug 2023 23:00:14 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DE04663C6D; Mon, 14 Aug 2023 23:00:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04BE6C433C8; Mon, 14 Aug 2023 23:00:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692054011; bh=EGJa219ihsXwvLRWPwGjLPQ3UTuDHjV8KLOtyo3Xz5M=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=pyhcsuGhgXNLbgCZ/if9Xu8DF/2u9Ax1DOX6dC4ngl9hHTcVkYVhQf3tOAe0OjwVm PpklY7mWveA1pALcUTFYqOm9z6mKj/PazrqpffyWSJY8AxnhkdBdrdqa4ZbwDxDAry ya8myKXKh0pGTK5B5xwK/MAK/LasV/V1OJdH0ipv3+VNos/vD0C3gxcI7H5TQR8CvZ rR1+fwslOxyyp29K35WAU41hWP57hJBc4b0fy78cwIr4dnBFcDABQCZ4qvSx+QSRNs lJbGEcI3M8WB29JPfGg4Eb2CO5vlmfcZoMRJBXXzcySJzCTkhnOXMwAvnEGXlLDhga w1DyPKBO92mPQ== Date: Mon, 14 Aug 2023 18:00:08 -0500 From: Bjorn Helgaas To: Justin Stitt Cc: Lorenzo Pieralisi , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Rob Herring , Bjorn Helgaas , Ray Jui , Scott Branden , Broadcom internal kernel review list , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH] PCI: iproc: fix -Wvoid-pointer-to-enum-cast warning Message-ID: <20230814230008.GA196797@bhelgaas> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230814-void-drivers-pci-controller-pcie-iproc-platform-v1-1-81a121607851@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230814_160012_737919_58A802C8 X-CRM114-Status: GOOD ( 24.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Aug 14, 2023 at 10:29:22PM +0000, Justin Stitt wrote: > When building with clang 18 I see the following warning: > | drivers/pci/controller/pcie-iproc-platform.c:55:15: warning: cast to smaller > | integer type 'enum iproc_pcie_type' from 'const void *' [-Wvoid-pointer-to-enum-cast] > | 55 | pcie->type = (enum iproc_pcie_type) of_device_get_match_data(dev); > > This is due to the fact that `of_device_get_match_data` returns a void* > while `enum iproc_pcie_type` has the size of an int. This leads to > truncation and possible data loss. > > Link: https://github.com/ClangBuiltLinux/linux/issues/1910 > Reported-by: Nathan Chancellor > Signed-off-by: Justin Stitt > --- > Note: There is likely no data loss occurring here since `enum > iproc_pcie_type` has only a few fields enumerated from 0. Definitely not > enough to cause data loss from pointer-width to int-width. > --- > drivers/pci/controller/pcie-iproc-platform.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/pci/controller/pcie-iproc-platform.c b/drivers/pci/controller/pcie-iproc-platform.c > index acdc583d2980..83cbc95f4384 100644 > --- a/drivers/pci/controller/pcie-iproc-platform.c > +++ b/drivers/pci/controller/pcie-iproc-platform.c > @@ -52,7 +52,7 @@ static int iproc_pltfm_pcie_probe(struct platform_device *pdev) > pcie = pci_host_bridge_priv(bridge); > > pcie->dev = dev; > - pcie->type = (enum iproc_pcie_type) of_device_get_match_data(dev); > + pcie->type = (uintptr_t) of_device_get_match_data(dev); This seems a little ugly on both ends: we have to cast the enum to (int *) in the of_device_id table: static const struct of_device_id iproc_pcie_of_match_table[] = { { .compatible = "brcm,iproc-pcie", .data = (int *)IPROC_PCIE_PAXB, }, and then we have to cast it back to the the enum type here, and we can't even use the actual enum type: pcie->type = (uintptr_t) of_device_get_match_data(dev); I think this would be nicer if we made a struct iproc_pcie_of_data along the lines of ks_pcie_of_data and put the enum values in instances of that struct. It's definitely a little more code and space, but it might also help us get rid of some of the "switch (pcie->type)" stuff scattered around this driver. Bjorn _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel