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 X-Spam-Level: X-Spam-Status: No, score=-4.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 671C9C18E5B for ; Tue, 10 Mar 2020 15:31:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3EFEC20578 for ; Tue, 10 Mar 2020 15:31:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583854300; bh=Uo1TDOeLFo1Wguk9igTKm1HigZCW2NY+t8xJKcLUdw0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=elnxOfIY3+CG+xTpaSD9WJWcN+Nk+2R3lhZNnfdPSxqY7q3NIpbE2Ipt1dBA7B//4 BXiT+OcKuf7ANfPQhIXFxxebHvgmVczDUTiUYkUvqfDxYbsYkGZYpioYDVK2obzTU2 ITXkquiiJydWFrYGjTyW5vGqhC79dF6fusIw5m3k= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727681AbgCJPbj (ORCPT ); Tue, 10 Mar 2020 11:31:39 -0400 Received: from conssluserg-02.nifty.com ([210.131.2.81]:46015 "EHLO conssluserg-02.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726420AbgCJPbj (ORCPT ); Tue, 10 Mar 2020 11:31:39 -0400 Received: from mail-vk1-f181.google.com (mail-vk1-f181.google.com [209.85.221.181]) (authenticated) by conssluserg-02.nifty.com with ESMTP id 02AFVYF4029019; Wed, 11 Mar 2020 00:31:34 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-02.nifty.com 02AFVYF4029019 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1583854295; bh=cU9zGQWEYLmKu3ABbJP9fWNhvET72vVMMuEoK2xZbeA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=uBFbZowblEtMMMtmmPl1g2DHYesZd0O3dcspp/C1j7pYuuZiW7+A/50a8OxAD9sGX 3LR/6esVVadbdu8bba9C/iyNdz3dcV1XCPR8GGy8utGuvugcaQ3MEfylMfUIJDhMlc NG5vO76Han+PqEgbLSWPcOmKIEPTutMTSJ6dyhq7dpIkAXIgNcot9dq/L918KUFXBu q9NuQO9PRXoSuGMXGCJbNN9TfnWlWmC97te5FfbTjQxdYauJy0Gw7S/20R3mgtEzV3 16OaLPqNErNEHNFQgVtuKtUqoV+aSA0TJIcw56ttliWlmuWvG/pJxx/tbqL5XKtYis myG5OlrsN218A== X-Nifty-SrcIP: [209.85.221.181] Received: by mail-vk1-f181.google.com with SMTP id i78so3679380vke.0; Tue, 10 Mar 2020 08:31:34 -0700 (PDT) X-Gm-Message-State: ANhLgQ3vCFmusR8luwcYaMMcsI3mZ2mG7fV4UiJqXUPY8wbCJC5dlOnf zMTXqPz5XlTk+nd2QFV2Ims2XOVspzBgT7y5L3k= X-Google-Smtp-Source: ADFU+vshzsYrewZL9/qV8QBmAcUvMQcoFa4yNoeetgkikl+9ovLz5Pmn2O39v6n04YVWO2hgbFnjooVJIw0mOh6UFtA= X-Received: by 2002:a1f:900c:: with SMTP id s12mr2563486vkd.96.1583854293448; Tue, 10 Mar 2020 08:31:33 -0700 (PDT) MIME-Version: 1.0 References: <20200308073400.23398-1-natechancellor@gmail.com> <20200310012545.GA16822@ubuntu-m2-xlarge-x86> In-Reply-To: From: Masahiro Yamada Date: Wed, 11 Mar 2020 00:30:57 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] kbuild: Disable -Wpointer-to-enum-cast To: David Laight Cc: Nathan Chancellor , Michal Marek , Linux Kbuild mailing list , Linux Kernel Mailing List , clang-built-linux , stable Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 10, 2020 at 8:31 PM David Laight wrote: > > From: Nathan Chancellor > > Sent: 10 March 2020 01:26 > ... > > Sure, I can send v2 to do that but I think that sending 97 patches just > > casting the small values (usually less than twenty) to unsigned long > > then to the enum is rather frivolous. I audited at least ten to fifteen > > of these call sites when creating the clang patch and they are all > > basically false positives. > > Such casts just make the code hard to read. > If misused casts can hide horrid bugs. > IMHO sprinkling the code with casts just to remove > compiler warnings will bite back one day. > I agree that too much casts make the code hard to read, but irrespective of this patch, there is no difference in the fact that we need a cast to convert (const void *) to a non-pointer value. The difference is whether we use (uintptr_t) or (enum foo). If we want to avoid casts completely, we could use union in struct of_device_id although this might be rejected. FWIW: diff --git a/drivers/ata/ahci_brcm.c b/drivers/ata/ahci_brcm.c index 6853dbb4131d..534170bea134 100644 --- a/drivers/ata/ahci_brcm.c +++ b/drivers/ata/ahci_brcm.c @@ -415,11 +415,11 @@ static struct scsi_host_template ahci_platform_sht = { }; static const struct of_device_id ahci_of_match[] = { - {.compatible = "brcm,bcm7425-ahci", .data = (void *)BRCM_SATA_BCM7425}, - {.compatible = "brcm,bcm7445-ahci", .data = (void *)BRCM_SATA_BCM7445}, - {.compatible = "brcm,bcm63138-ahci", .data = (void *)BRCM_SATA_BCM7445}, - {.compatible = "brcm,bcm-nsp-ahci", .data = (void *)BRCM_SATA_NSP}, - {.compatible = "brcm,bcm7216-ahci", .data = (void *)BRCM_SATA_BCM7216}, + {.compatible = "brcm,bcm7425-ahci", .data2 = BRCM_SATA_BCM7425}, + {.compatible = "brcm,bcm7445-ahci", .data2 = BRCM_SATA_BCM7445}, + {.compatible = "brcm,bcm63138-ahci", .data2 = BRCM_SATA_BCM7445}, + {.compatible = "brcm,bcm-nsp-ahci", .data2 = BRCM_SATA_NSP}, + {.compatible = "brcm,bcm7216-ahci", .data2 = BRCM_SATA_BCM7216}, {}, }; MODULE_DEVICE_TABLE(of, ahci_of_match); @@ -442,7 +442,7 @@ static int brcm_ahci_probe(struct platform_device *pdev) if (!of_id) return -ENODEV; - priv->version = (enum brcm_ahci_version)of_id->data; + priv->version = of_id->data2; priv->dev = dev; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "top-ctrl"); diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h index e3596db077dc..98d44ebf146a 100644 --- a/include/linux/mod_devicetable.h +++ b/include/linux/mod_devicetable.h @@ -261,7 +261,10 @@ struct of_device_id { char name[32]; char type[32]; char compatible[128]; - const void *data; + union { + const void *data; + unsigned long data2; + }; }; /* VIO */ -- Best Regards Masahiro Yamada