Use spi_get_device_match_data() helper to simplify a bit the driver.
Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
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);
priv->net = net;
priv->clk = clk;
--
2.43.0
Use spi_get_device_match_data() helper to simplify a bit the driver.
Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/net/can/spi/mcp251x.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c
index 79c4bab5f724..85998b4b08c3 100644
--- a/drivers/net/can/spi/mcp251x.c
+++ b/drivers/net/can/spi/mcp251x.c
@@ -1301,7 +1301,6 @@ MODULE_DEVICE_TABLE(spi, mcp251x_id_table);
static int mcp251x_can_probe(struct spi_device *spi)
{
- const void *match = device_get_match_data(&spi->dev);
struct net_device *net;
struct mcp251x_priv *priv;
struct clk *clk;
@@ -1339,10 +1338,7 @@ static int mcp251x_can_probe(struct spi_device *spi)
priv->can.clock.freq = freq / 2;
priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES |
CAN_CTRLMODE_LOOPBACK | CAN_CTRLMODE_LISTENONLY;
- if (match)
- priv->model = (enum mcp251x_model)(uintptr_t)match;
- else
- priv->model = spi_get_device_id(spi)->driver_data;
+ priv->model = (enum mcp251x_model)spi_get_device_match_data(spi);
priv->net = net;
priv->clk = clk;
--
2.43.0
Use spi_get_device_match_data() helper to simplify a bit the driver.
Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
index 1d9057dc44f2..4b7e08e8ed56 100644
--- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
+++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
@@ -1989,7 +1989,6 @@ MODULE_DEVICE_TABLE(spi, mcp251xfd_id_table);
static int mcp251xfd_probe(struct spi_device *spi)
{
- const void *match;
struct net_device *ndev;
struct mcp251xfd_priv *priv;
struct gpio_desc *rx_int;
@@ -2081,13 +2080,7 @@ static int mcp251xfd_probe(struct spi_device *spi)
priv->pll_enable = pll_enable;
priv->reg_vdd = reg_vdd;
priv->reg_xceiver = reg_xceiver;
-
- match = device_get_match_data(&spi->dev);
- if (match)
- priv->devtype_data = *(struct mcp251xfd_devtype_data *)match;
- else
- priv->devtype_data = *(struct mcp251xfd_devtype_data *)
- spi_get_device_id(spi)->driver_data;
+ priv->devtype_data = *(struct mcp251xfd_devtype_data *)spi_get_device_match_data(spi);
/* Errata Reference:
* mcp2517fd: DS80000792C 5., mcp2518fd: DS80000789C 4.
--
2.43.0
Hi Krzysztof,
On Thu. 6 Jun. 2024 à 23:24, Krzysztof Kozlowski
<[email protected]> wrote:
> Use spi_get_device_match_data() helper to simplify a bit the driver.
Thanks for this clean up.
> Signed-off-by: Krzysztof Kozlowski <[email protected]>
> ---
> 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/[email protected]/
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