lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20230814230008.GA196797@bhelgaas>
Date:   Mon, 14 Aug 2023 18:00:08 -0500
From:   Bjorn Helgaas <helgaas@...nel.org>
To:     Justin Stitt <justinstitt@...gle.com>
Cc:     Lorenzo Pieralisi <lpieralisi@...nel.org>,
        Krzysztof WilczyƄski <kw@...ux.com>,
        Rob Herring <robh@...nel.org>,
        Bjorn Helgaas <bhelgaas@...gle.com>,
        Ray Jui <rjui@...adcom.com>,
        Scott Branden <sbranden@...adcom.com>,
        Broadcom internal kernel review list 
        <bcm-kernel-feedback-list@...adcom.com>,
        Nathan Chancellor <nathan@...nel.org>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Tom Rix <trix@...hat.com>, linux-pci@...r.kernel.org,
        linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
        llvm@...ts.linux.dev
Subject: Re: [PATCH] PCI: iproc: fix -Wvoid-pointer-to-enum-cast warning

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 <nathan@...nel.org>
> Signed-off-by: Justin Stitt <justinstitt@...gle.com>
> ---
> 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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ