Message ID | 20230810085042.39252-1-krzysztof.kozlowski@linaro.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp296571vqi; Thu, 10 Aug 2023 02:35:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHg9V1F1szcx9Jhv3Hh0I/tiybce4ydNNkuSEaeYlJ1N7R8kVsE5JOFM7VEE/WdgW4bnW0h X-Received: by 2002:a17:902:e751:b0:1bc:9651:57c6 with SMTP id p17-20020a170902e75100b001bc965157c6mr2279205plf.57.1691660157880; Thu, 10 Aug 2023 02:35:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691660157; cv=none; d=google.com; s=arc-20160816; b=hHzwPv0kVkie0JTWM/yV9j6X6bXh0wBWUiXO7pkEvPgXz3BrmJtVN2d1Wth5l9/9ks Yw0BaaDCuwQ8BmjwqOmUPCoxZKyRa2EDlsdU1wSwurJdnaaqkLb9BsGqqRMSFgRcf0/i 8AQ2R+QjlEXuRIbpHpXycZN+OzQnFGoiPX3UrsxkzeDNFnqte1AxyJgq4G9CdzNfSQ73 zg1ttHqfNhQ7eeiWWv7DvQnCFByTQTxD7gbzzTpe/cBO4w8mvQ3trYy5MleYYtSK6Udu Lc9AZ45vl81/DT7DE5ZYyVwvpDKNMkRDM0ifLi8z3VzntUogtX2Gi2GfiZvKiFCLBQ9L eL3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=zUA6Uop1470tUJbDViYaX4LRHpvZYJIyke3HCwbN6+o=; fh=PUC8ZRfJah6QXsUBAci19KSZLxKoUq3tXPiPZBQIZoQ=; b=NqDWVslUztZWLQU2hSPXtk750rOv3AlUgHg9JhcMgzTScdU45pwHSUhMSpgmRMP5pH xg/FbPwGGNSx8ilaRCZLs7MrbPRMN+vJkB1y9pmC0LaEolcwlQMzXsNaQb07LziTWuSJ Qt21sJ9NMB/4BP8H8/mN/w1TZYYCnjSsrAu9sNaq+OA1mMPrdA9E0cMFbjOQ1fnpJluR ss5rQNJ2YZoQxQTkik4sjwgDFZXM/U6lqa3Lc4RtSBLsWaTnkPAdrFRe6EOaGYdjKMch LgYziEUslNaOQUcOAd+bZNtyzJtQwEFnQW75zEavB0p5ZfPaKZjUleNIeJTzaSa/EVBx PfFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o2dv9R0J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p1-20020a170902e74100b001bbad3b063bsi1199295plf.345.2023.08.10.02.35.38; Thu, 10 Aug 2023 02:35:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o2dv9R0J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234357AbjHJIut (ORCPT <rfc822;m15293943392@gmail.com> + 99 others); Thu, 10 Aug 2023 04:50:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229604AbjHJIus (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 10 Aug 2023 04:50:48 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A8981BFA for <linux-kernel@vger.kernel.org>; Thu, 10 Aug 2023 01:50:47 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-317716a4622so641920f8f.1 for <linux-kernel@vger.kernel.org>; Thu, 10 Aug 2023 01:50:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691657446; x=1692262246; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=zUA6Uop1470tUJbDViYaX4LRHpvZYJIyke3HCwbN6+o=; b=o2dv9R0JA3ZxL9ing7at6nqKjTLilmMT0IQRbfsOpS8nBL9yjoITmy2fRO+my3ZMRu s+5a+R+fxQDERaGpBHUyUsDhTzQNOaKC1pNAuNA+P2i1Xra3XgkKLHODmJEyEABz5lIc TXXVcRuElWHjZU30tkr19+P3PI+9FiD2x5wOPq0sKGOuxqcPPX5lDd0IdorEgvYuO69p y+gy90/0W/HJqjb4yqVFS9X0OzWyl7T/ieaeEWoX9DIa9bDckj/75hVKwniRSqhnIkHo Z/2LKe7ax2ZNTZUzXO+Wr1qNfv94J30qMRMfgJb1ULBW+y9rLXuhZHfbeeMvy2Gto9tr s/iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691657446; x=1692262246; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zUA6Uop1470tUJbDViYaX4LRHpvZYJIyke3HCwbN6+o=; b=TCVb/95oIrrBHX+Clr9crBjsbPOXqIu4dir+Rrazql/sGsWs20nxxBQf2BItEPpxbT 2Xx3XAmCzGqFNLRNxkF8dyDsG+YE9sp0sWGzw67dELi9c8FlkUaFSiGlnscXVsgf+eMj Ns1d2Dnp20OW78yk2bB544yJRy6ZwbN2Gyfu7R7WlacgacNR0eoKH9/bgOSrCiD100FQ H0zRshN15BnixtoPW9b97WbdgePc7JuW4Ss4Fio4sMfuzHTka/kNGitoJJfw3Z6fKJwD KLfx6oht1SzwaKhI2In8B4aWiaQXtxZF0CRkOSjHFTYpiMVnf5RBGa5a283W8R6Qj5UI dISg== X-Gm-Message-State: AOJu0YxGtLoOw0u2rDkdjsW1hg0CFL7WfShjr9rN0h6ELKxUiuROBCd0 3tIzUlSM9MvDlhvTkVfQGOkKRg== X-Received: by 2002:adf:f011:0:b0:317:43e0:3f47 with SMTP id j17-20020adff011000000b0031743e03f47mr1605618wro.36.1691657445994; Thu, 10 Aug 2023 01:50:45 -0700 (PDT) Received: from krzk-bin.. ([178.197.222.113]) by smtp.gmail.com with ESMTPSA id q11-20020adfcd8b000000b003180155493esm1395013wrj.67.2023.08.10.01.50.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 01:50:45 -0700 (PDT) From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Jiri Slaby <jirislaby@kernel.org>, Shawn Guo <shawnguo@kernel.org>, Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix Kernel Team <kernel@pengutronix.de>, Fabio Estevam <festevam@gmail.com>, NXP Linux Team <linux-imx@nxp.com>, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>, Andi Shyti <andi.shyti@kernel.org> Subject: [PATCH] serial: mxs-uart: fix Wvoid-pointer-to-enum-cast warning Date: Thu, 10 Aug 2023 10:50:42 +0200 Message-Id: <20230810085042.39252-1-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773834241755666733 X-GMAIL-MSGID: 1773834241755666733 |
Series |
serial: mxs-uart: fix Wvoid-pointer-to-enum-cast warning
|
|
Commit Message
Krzysztof Kozlowski
Aug. 10, 2023, 8:50 a.m. UTC
`devtype` is enum, thus cast of pointer on 64-bit compile test with W=1
causes:
mxs-auart.c:1598:15: error: cast to smaller integer type 'enum mxs_auart_type' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]
Cc: Andi Shyti <andi.shyti@kernel.org>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
drivers/tty/serial/mxs-auart.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Thu, Aug 10, 2023 at 10:50:42AM +0200, Krzysztof Kozlowski wrote: > `devtype` is enum, thus cast of pointer on 64-bit compile test with W=1 > causes: > > mxs-auart.c:1598:15: error: cast to smaller integer type 'enum mxs_auart_type' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast] > > Cc: Andi Shyti <andi.shyti@kernel.org> > Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> > --- > drivers/tty/serial/mxs-auart.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c > index 8eeecf8ad359..a9b32722b049 100644 > --- a/drivers/tty/serial/mxs-auart.c > +++ b/drivers/tty/serial/mxs-auart.c > @@ -1595,7 +1595,7 @@ static int mxs_auart_probe(struct platform_device *pdev) > return -EINVAL; > } > > - s->devtype = (enum mxs_auart_type)of_device_get_match_data(&pdev->dev); > + s->devtype = (uintptr_t)of_device_get_match_data(&pdev->dev); This feels like a compiler issue as devtype is a enum mxs_auart_type variable, so the cast shoudl be correct. And if not, unitptr_t isn't a valid kernel type, so that's not a good solution either. Worst case, it's how big a pointer is, which is not going to be what an enum is if you have a sane compiler :( thanks, greg k-h
On 10/08/2023 17:44, Greg Kroah-Hartman wrote: > On Thu, Aug 10, 2023 at 10:50:42AM +0200, Krzysztof Kozlowski wrote: >> `devtype` is enum, thus cast of pointer on 64-bit compile test with W=1 >> causes: >> >> mxs-auart.c:1598:15: error: cast to smaller integer type 'enum mxs_auart_type' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast] >> >> Cc: Andi Shyti <andi.shyti@kernel.org> >> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> >> --- >> drivers/tty/serial/mxs-auart.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c >> index 8eeecf8ad359..a9b32722b049 100644 >> --- a/drivers/tty/serial/mxs-auart.c >> +++ b/drivers/tty/serial/mxs-auart.c >> @@ -1595,7 +1595,7 @@ static int mxs_auart_probe(struct platform_device *pdev) >> return -EINVAL; >> } >> >> - s->devtype = (enum mxs_auart_type)of_device_get_match_data(&pdev->dev); >> + s->devtype = (uintptr_t)of_device_get_match_data(&pdev->dev); > > This feels like a compiler issue as devtype is a enum mxs_auart_type > variable, so the cast shoudl be correct. While the cast is obviously safe here, the warning in general is reasonable - people were make too many mistakes by assuming pointers are integers... Just for the record (not saying that others doing is proof of correctness): https://lore.kernel.org/lkml/20230809-cbl-1903-v1-1-df9d66a3ba3e@google.com/T/ But maybe Nathan can share his thoughts whether we should just disable this warning for kernel? > > And if not, unitptr_t isn't a valid kernel type, so that's not a good It is in include/linux/types.h, so do you mean that it is not recommended for in-kernel usage? I can go with kernel_ulong_t - which is a kernel type - if the cast is agreed. > solution either. Worst case, it's how big a pointer is, which is not > going to be what an enum is if you have a sane compiler :( Best regards, Krzysztof
On Mon, Aug 14, 2023 at 08:58:34AM +0200, Krzysztof Kozlowski wrote: > On 10/08/2023 17:44, Greg Kroah-Hartman wrote: > > On Thu, Aug 10, 2023 at 10:50:42AM +0200, Krzysztof Kozlowski wrote: > >> `devtype` is enum, thus cast of pointer on 64-bit compile test with W=1 > >> causes: > >> > >> mxs-auart.c:1598:15: error: cast to smaller integer type 'enum mxs_auart_type' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast] > >> > >> Cc: Andi Shyti <andi.shyti@kernel.org> > >> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> > >> --- > >> drivers/tty/serial/mxs-auart.c | 2 +- > >> 1 file changed, 1 insertion(+), 1 deletion(-) > >> > >> diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c > >> index 8eeecf8ad359..a9b32722b049 100644 > >> --- a/drivers/tty/serial/mxs-auart.c > >> +++ b/drivers/tty/serial/mxs-auart.c > >> @@ -1595,7 +1595,7 @@ static int mxs_auart_probe(struct platform_device *pdev) > >> return -EINVAL; > >> } > >> > >> - s->devtype = (enum mxs_auart_type)of_device_get_match_data(&pdev->dev); > >> + s->devtype = (uintptr_t)of_device_get_match_data(&pdev->dev); > > > > This feels like a compiler issue as devtype is a enum mxs_auart_type > > variable, so the cast shoudl be correct. > > While the cast is obviously safe here, the warning in general is > reasonable - people were make too many mistakes by assuming pointers are > integers... But this isn't a pointer, it's an enumerated type thrown into a void *, so cast it properly (void * == unsigned long). > Just for the record (not saying that others doing is proof of correctness): > > https://lore.kernel.org/lkml/20230809-cbl-1903-v1-1-df9d66a3ba3e@google.com/T/ > > But maybe Nathan can share his thoughts whether we should just disable > this warning for kernel? I thought that Linus had some objection to the compilers doing something foolish here as well, but I can't find it in my archives at the moment (am traveling). > > And if not, unitptr_t isn't a valid kernel type, so that's not a good > > It is in include/linux/types.h, so do you mean that it is not > recommended for in-kernel usage? I can go with kernel_ulong_t - which is > a kernel type - if the cast is agreed. not recommended for in-kernel usage. thanks, greg k-h
On Mon, Aug 14, 2023 at 08:58:34AM +0200, Krzysztof Kozlowski wrote: > On 10/08/2023 17:44, Greg Kroah-Hartman wrote: > > On Thu, Aug 10, 2023 at 10:50:42AM +0200, Krzysztof Kozlowski wrote: > >> `devtype` is enum, thus cast of pointer on 64-bit compile test with W=1 > >> causes: > >> > >> mxs-auart.c:1598:15: error: cast to smaller integer type 'enum mxs_auart_type' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast] > >> > >> Cc: Andi Shyti <andi.shyti@kernel.org> > >> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> > >> --- > >> drivers/tty/serial/mxs-auart.c | 2 +- > >> 1 file changed, 1 insertion(+), 1 deletion(-) > >> > >> diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c > >> index 8eeecf8ad359..a9b32722b049 100644 > >> --- a/drivers/tty/serial/mxs-auart.c > >> +++ b/drivers/tty/serial/mxs-auart.c > >> @@ -1595,7 +1595,7 @@ static int mxs_auart_probe(struct platform_device *pdev) > >> return -EINVAL; > >> } > >> > >> - s->devtype = (enum mxs_auart_type)of_device_get_match_data(&pdev->dev); > >> + s->devtype = (uintptr_t)of_device_get_match_data(&pdev->dev); > > > > This feels like a compiler issue as devtype is a enum mxs_auart_type > > variable, so the cast shoudl be correct. > > While the cast is obviously safe here, the warning in general is > reasonable - people were make too many mistakes by assuming pointers are > integers... Yeah, this is just a variant of -Wvoid-pointer-to-int-cast, which itself is a variant of -Wpointer-to-int-cast. When clang implemented that warning, it chose to warn for both (int) and (enum ...) casts, whereas GCC just warns for int casts: https://godbolt.org/z/G8xsYqbzP I brought up that difference to the clang folks and they justified it well I think: https://reviews.llvm.org/D72231#1881784 > Just for the record (not saying that others doing is proof of correctness): > > https://lore.kernel.org/lkml/20230809-cbl-1903-v1-1-df9d66a3ba3e@google.com/T/ > > But maybe Nathan can share his thoughts whether we should just disable > this warning for kernel? Technically, it is disabled for a regular kernel build but it shows up with W=1: https://git.kernel.org/linus/82f2bc2fcc0160d6f82dd1ac64518ae0a4dd183f That was not done because the warning was wrong but because we were working hard to drive the warning count down to zero and did not want to have to solve the 90+ instances that were around at that time. Now, with the patches that you have sent and the ones that Justin is working on, we are much closer: https://github.com/ClangBuiltLinux/linux/issues/1910#issuecomment-1675563993 > > And if not, unitptr_t isn't a valid kernel type, so that's not a good > > It is in include/linux/types.h, so do you mean that it is not > recommended for in-kernel usage? I can go with kernel_ulong_t - which is > a kernel type - if the cast is agreed. uintptr_t is used quite a bit in the kernel already, so I don't really get the "not a valid kernel type" argument. I have seen other folks prefer 'unsigned long' since Linux assumes it has the same size as a pointer but that is what uintptr_t is supposed to be... Cheers, Nathan
diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c index 8eeecf8ad359..a9b32722b049 100644 --- a/drivers/tty/serial/mxs-auart.c +++ b/drivers/tty/serial/mxs-auart.c @@ -1595,7 +1595,7 @@ static int mxs_auart_probe(struct platform_device *pdev) return -EINVAL; } - s->devtype = (enum mxs_auart_type)of_device_get_match_data(&pdev->dev); + s->devtype = (uintptr_t)of_device_get_match_data(&pdev->dev); ret = mxs_get_clks(s, pdev); if (ret)