diff mbox series

[net-next,1/3] can: hi311x: simplify with spi_get_device_match_data()

Message ID 20240606142424.129709-1-krzysztof.kozlowski@linaro.org (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series [net-next,1/3] can: hi311x: simplify with spi_get_device_match_data() | expand

Checks

Context Check Description
netdev/series_format warning Series does not have a cover letter
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 901 this patch: 901
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang fail Errors and warnings before: 905 this patch: 907
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 905 this patch: 905
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 19 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Krzysztof Kozlowski June 6, 2024, 2:24 p.m. UTC
Use spi_get_device_match_data() helper to simplify a bit the driver.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/net/can/spi/hi311x.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

Comments

Vincent Mailhol June 7, 2024, 3:26 a.m. UTC | #1
Hi Krzysztof,

On Thu. 6 Jun. 2024 à 23:24, Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:
> Use spi_get_device_match_data() helper to simplify a bit the driver.

Thanks for this clean up.

> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
>  drivers/net/can/spi/hi311x.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c
> index e1b8533a602e..5d2c80f05611 100644
> --- a/drivers/net/can/spi/hi311x.c
> +++ b/drivers/net/can/spi/hi311x.c
> @@ -830,7 +830,6 @@ static int hi3110_can_probe(struct spi_device *spi)
>         struct device *dev = &spi->dev;
>         struct net_device *net;
>         struct hi3110_priv *priv;
> -       const void *match;
>         struct clk *clk;
>         u32 freq;
>         int ret;
> @@ -874,11 +873,7 @@ static int hi3110_can_probe(struct spi_device *spi)
>                 CAN_CTRLMODE_LISTENONLY |
>                 CAN_CTRLMODE_BERR_REPORTING;
>
> -       match = device_get_match_data(dev);
> -       if (match)
> -               priv->model = (enum hi3110_model)(uintptr_t)match;
> -       else
> -               priv->model = spi_get_device_id(spi)->driver_data;
> +       priv->model = (enum hi3110_model)spi_get_device_match_data(spi);

Here, you are dropping the (uintptr_t) cast. Casting a pointer to an
enum type can trigger a zealous -Wvoid-pointer-to-enum-cast clang
warning, and the (uintptr_t) cast is the defacto standard to silence
such warnings, thus the double (enum hi3110_model)(uintptr_t) cast in
the initial version.

Refer to this thread for examples:

  https://lore.kernel.org/linux-can/20210527084532.1384031-12-mkl@pengutronix.de/

Unless you are able to add a rationale in the patch description of why
this cast can now be removed, I suggest you to keep it:

          priv->model = (enum
hi3110_model)(uintptr_t)spi_get_device_match_data(spi);

>         priv->net = net;
>         priv->clk = clk;

Yours sincerely,
Vincent Mailhol
Marc Kleine-Budde June 20, 2024, 12:20 p.m. UTC | #2
On 07.06.2024 12:26:13, Vincent MAILHOL wrote:
> Hi Krzysztof,
> 
> On Thu. 6 Jun. 2024 à 23:24, Krzysztof Kozlowski
> <krzysztof.kozlowski@linaro.org> wrote:
> > Use spi_get_device_match_data() helper to simplify a bit the driver.
> 
> Thanks for this clean up.
> 
> > Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> > ---
> >  drivers/net/can/spi/hi311x.c | 7 +------
> >  1 file changed, 1 insertion(+), 6 deletions(-)
> >
> > diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c
> > index e1b8533a602e..5d2c80f05611 100644
> > --- a/drivers/net/can/spi/hi311x.c
> > +++ b/drivers/net/can/spi/hi311x.c
> > @@ -830,7 +830,6 @@ static int hi3110_can_probe(struct spi_device *spi)
> >         struct device *dev = &spi->dev;
> >         struct net_device *net;
> >         struct hi3110_priv *priv;
> > -       const void *match;
> >         struct clk *clk;
> >         u32 freq;
> >         int ret;
> > @@ -874,11 +873,7 @@ static int hi3110_can_probe(struct spi_device *spi)
> >                 CAN_CTRLMODE_LISTENONLY |
> >                 CAN_CTRLMODE_BERR_REPORTING;
> >
> > -       match = device_get_match_data(dev);
> > -       if (match)
> > -               priv->model = (enum hi3110_model)(uintptr_t)match;
> > -       else
> > -               priv->model = spi_get_device_id(spi)->driver_data;
> > +       priv->model = (enum hi3110_model)spi_get_device_match_data(spi);
> 
> Here, you are dropping the (uintptr_t) cast. Casting a pointer to an
> enum type can trigger a zealous -Wvoid-pointer-to-enum-cast clang
> warning, and the (uintptr_t) cast is the defacto standard to silence
> such warnings, thus the double (enum hi3110_model)(uintptr_t) cast in
> the initial version.

I've re-added the intermediate cast to uintptr_t while applying.

Thanks,
Marc
Marc Kleine-Budde June 21, 2024, 8:30 a.m. UTC | #3
On 20.06.2024 14:20:53, Marc Kleine-Budde wrote:
> On 07.06.2024 12:26:13, Vincent MAILHOL wrote:
> > Hi Krzysztof,
> > 
> > On Thu. 6 Jun. 2024 à 23:24, Krzysztof Kozlowski
> > <krzysztof.kozlowski@linaro.org> wrote:
> > > Use spi_get_device_match_data() helper to simplify a bit the driver.
> > 
> > Thanks for this clean up.
> > 
> > > Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> > > ---
> > >  drivers/net/can/spi/hi311x.c | 7 +------
> > >  1 file changed, 1 insertion(+), 6 deletions(-)
> > >
> > > diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c
> > > index e1b8533a602e..5d2c80f05611 100644
> > > --- a/drivers/net/can/spi/hi311x.c
> > > +++ b/drivers/net/can/spi/hi311x.c
> > > @@ -830,7 +830,6 @@ static int hi3110_can_probe(struct spi_device *spi)
> > >         struct device *dev = &spi->dev;
> > >         struct net_device *net;
> > >         struct hi3110_priv *priv;
> > > -       const void *match;
> > >         struct clk *clk;
> > >         u32 freq;
> > >         int ret;
> > > @@ -874,11 +873,7 @@ static int hi3110_can_probe(struct spi_device *spi)
> > >                 CAN_CTRLMODE_LISTENONLY |
> > >                 CAN_CTRLMODE_BERR_REPORTING;
> > >
> > > -       match = device_get_match_data(dev);
> > > -       if (match)
> > > -               priv->model = (enum hi3110_model)(uintptr_t)match;
> > > -       else
> > > -               priv->model = spi_get_device_id(spi)->driver_data;
> > > +       priv->model = (enum hi3110_model)spi_get_device_match_data(spi);
> > 
> > Here, you are dropping the (uintptr_t) cast. Casting a pointer to an
> > enum type can trigger a zealous -Wvoid-pointer-to-enum-cast clang
> > warning, and the (uintptr_t) cast is the defacto standard to silence
> > such warnings, thus the double (enum hi3110_model)(uintptr_t) cast in
> > the initial version.
> 
> I've re-added the intermediate cast to uintptr_t while applying.

Applied to linux-can-next.

Thanks,
Marc
diff mbox series

Patch

diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c
index e1b8533a602e..5d2c80f05611 100644
--- a/drivers/net/can/spi/hi311x.c
+++ b/drivers/net/can/spi/hi311x.c
@@ -830,7 +830,6 @@  static int hi3110_can_probe(struct spi_device *spi)
 	struct device *dev = &spi->dev;
 	struct net_device *net;
 	struct hi3110_priv *priv;
-	const void *match;
 	struct clk *clk;
 	u32 freq;
 	int ret;
@@ -874,11 +873,7 @@  static int hi3110_can_probe(struct spi_device *spi)
 		CAN_CTRLMODE_LISTENONLY |
 		CAN_CTRLMODE_BERR_REPORTING;
 
-	match = device_get_match_data(dev);
-	if (match)
-		priv->model = (enum hi3110_model)(uintptr_t)match;
-	else
-		priv->model = spi_get_device_id(spi)->driver_data;
+	priv->model = (enum hi3110_model)spi_get_device_match_data(spi);
 	priv->net = net;
 	priv->clk = clk;