* [PATCH 1/8] treewide: replace dev_get_drvdata with device_get_match_data
@ 2025-05-06 6:34 Ahmad Fatoum
2025-05-06 6:34 ` [PATCH 2/8] ARM: i.MX: esdctl: " Ahmad Fatoum
` (7 more replies)
0 siblings, 8 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2025-05-06 6:34 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Both Linux and barebox define a dev_get_drvdata function, but
annoyingly, the barebox version accesses the private data set in the
probe function, while the Linux version retrieves the match data set by
the driver core instead.
In preparation for changing the function to have the Linux semantics,
start by replacing most instances in barebox with device_get_match_data.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/boards/stm32mp15xx-dkx/board.c | 5 +++--
arch/arm/cpu/psci-client.c | 4 ++--
arch/arm/mach-imx/iim.c | 8 +++++---
drivers/ata/sata-imx.c | 8 ++++----
drivers/bus/imx-weim.c | 12 ++++++------
drivers/clocksource/timer-imx-gpt.c | 9 ++++-----
drivers/eeprom/at24.c | 6 +++---
drivers/firmware/altera_serial.c | 6 +++---
drivers/gpio/gpio-imx.c | 11 +++++------
drivers/gpio/gpio-omap.c | 4 ++--
drivers/gpio/gpio-pca953x.c | 8 +++-----
drivers/gpio/gpio-pcf857x.c | 7 +++----
drivers/gpio/gpio-tegra.c | 12 +++++-------
drivers/gpio/gpio-vf610.c | 8 ++++----
drivers/i2c/busses/i2c-at91.c | 18 ++++++++----------
drivers/i2c/busses/i2c-mv64xxx.c | 4 ++--
drivers/i2c/busses/i2c-omap.c | 12 ++++++------
drivers/i2c/busses/i2c-stm32.c | 6 +++---
drivers/i2c/busses/i2c-tegra.c | 6 ++++--
drivers/mailbox/ti-msgmgr.c | 6 +++---
drivers/mci/am654-sdhci.c | 6 +++---
drivers/mci/imx-esdhc.c | 6 +++---
drivers/mci/omap_hsmmc.c | 7 +++----
drivers/mfd/mc13xxx.c | 8 ++++----
drivers/mtd/nand/raw/mxc_nand.c | 8 ++++----
drivers/mtd/nand/raw/nand_denali_dt.c | 8 ++++----
drivers/net/ag71xx.c | 9 ++++-----
drivers/net/designware.c | 16 ++++++----------
drivers/net/designware_imx.c | 10 +++++-----
drivers/net/designware_socfpga.c | 9 +++------
drivers/net/fec_imx.c | 6 +++---
drivers/net/fsl-fman.c | 7 +++----
drivers/nvmem/bsec.c | 6 +++---
drivers/nvmem/imx-ocotp-ele.c | 9 ++++-----
drivers/nvmem/ocotp.c | 6 +++---
drivers/pci/pci-tegra.c | 2 +-
drivers/pinctrl/pinctrl-at91.c | 8 +++-----
drivers/power/reset/syscon-reboot-mode.c | 8 ++++----
drivers/pwm/pwm-atmel.c | 6 +++---
drivers/pwm/pwm-imx.c | 7 +++----
drivers/rtc/rtc-ds1307.c | 8 ++++----
drivers/serial/serial_cadence.c | 10 +++++-----
drivers/serial/serial_imx.c | 10 +++++-----
drivers/serial/serial_lpuart32.c | 8 ++++----
drivers/serial/serial_stm32.c | 8 ++++----
drivers/spi/imx_spi.c | 6 +++---
drivers/spi/omap3_spi.c | 9 ++++-----
drivers/spi/spi-fsl-dspi.c | 4 ++--
drivers/usb/imx/chipidea-imx.c | 6 +++---
drivers/usb/imx/imx-usb-misc.c | 11 +++++------
drivers/usb/musb/musb_dsps.c | 6 +++---
drivers/usb/musb/phy-am335x-control.c | 6 +++---
drivers/video/atmel_lcdfb_core.c | 6 +++---
drivers/video/imx-ipu-v3/dw_hdmi-imx.c | 14 +++++++-------
drivers/video/imx-ipu-v3/imx-ldb.c | 6 +++---
drivers/video/imx-ipu-v3/ipu-common.c | 6 +++---
drivers/watchdog/f71808e_wdt.c | 7 +++----
drivers/watchdog/imxulp-wdt.c | 8 ++++----
drivers/watchdog/imxwd.c | 8 ++++----
drivers/watchdog/stm32_iwdg.c | 6 +++---
60 files changed, 222 insertions(+), 243 deletions(-)
diff --git a/arch/arm/boards/stm32mp15xx-dkx/board.c b/arch/arm/boards/stm32mp15xx-dkx/board.c
index 9f005ec1091f..d693bf2aaf68 100644
--- a/arch/arm/boards/stm32mp15xx-dkx/board.c
+++ b/arch/arm/boards/stm32mp15xx-dkx/board.c
@@ -6,12 +6,13 @@
static int dkx_probe(struct device *dev)
{
- const void *model;
+ const char *model;
stm32mp_bbu_mmc_fip_register("sd", "/dev/mmc0",
BBU_HANDLER_FLAG_DEFAULT);
- if (dev_get_drvdata(dev, &model) == 0)
+ model = device_get_match_data(dev);
+ if (model)
barebox_set_model(model);
barebox_set_hostname("stm32mp15xx-dkx");
diff --git a/arch/arm/cpu/psci-client.c b/arch/arm/cpu/psci-client.c
index 251a374eac80..4c26beacb9bb 100644
--- a/arch/arm/cpu/psci-client.c
+++ b/arch/arm/cpu/psci-client.c
@@ -121,8 +121,8 @@ static int __init psci_probe(struct device *dev)
ulong of_version, actual_version;
int ret;
- ret = dev_get_drvdata(dev, (const void **)&of_version);
- if (ret)
+ of_version = (uintptr_t)device_get_match_data(dev);
+ if (!of_version)
return -ENODEV;
ret = of_property_read_string(dev->of_node, "method", &method);
diff --git a/arch/arm/mach-imx/iim.c b/arch/arm/mach-imx/iim.c
index 7020e6eafa4f..9e8b82da0549 100644
--- a/arch/arm/mach-imx/iim.c
+++ b/arch/arm/mach-imx/iim.c
@@ -453,15 +453,17 @@ static int imx_iim_probe(struct device *dev)
struct resource *iores;
struct iim_priv *iim;
int i, ret;
- struct imx_iim_drvdata *drvdata = NULL;
- char *nregs = NULL;
+ const struct imx_iim_drvdata *drvdata;
+ const char *nregs = NULL;
if (imx_iim)
return -EBUSY;
iim = xzalloc(sizeof(*iim));
- dev_get_drvdata(dev, (const void **)&drvdata);
+ drvdata = device_get_match_data(dev);
+ if (!drvdata)
+ return -ENODEV;
if (drvdata && drvdata->supply)
iim->supply = drvdata->supply;
diff --git a/drivers/ata/sata-imx.c b/drivers/ata/sata-imx.c
index 3f49f70dcc3a..13c08f6f2a06 100644
--- a/drivers/ata/sata-imx.c
+++ b/drivers/ata/sata-imx.c
@@ -87,12 +87,12 @@ static int imx_sata_probe(struct device *dev)
{
struct resource *iores;
struct imx_ahci *imx_ahci;
- struct imx_sata_data *data;
+ const struct imx_sata_data *data;
int ret;
- ret = dev_get_drvdata(dev, (const void **)&data);
- if (ret)
- return ret;
+ data = device_get_match_data(dev);
+ if (!data)
+ return -ENODEV;
imx_ahci = xzalloc(sizeof(*imx_ahci));
diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
index 4907577164f9..50e210c16f33 100644
--- a/drivers/bus/imx-weim.c
+++ b/drivers/bus/imx-weim.c
@@ -69,14 +69,14 @@ MODULE_DEVICE_TABLE(of, weim_id_table);
struct imx_weim {
struct device *dev;
void __iomem *base;
- struct imx_weim_devtype *devtype;
+ const struct imx_weim_devtype *devtype;
};
/* Parse and set the timing for this device. */
static int
weim_timing_setup(struct imx_weim *weim, struct device_node *np)
{
- struct imx_weim_devtype *devtype = weim->devtype;
+ const struct imx_weim_devtype *devtype = weim->devtype;
u32 cs_idx, value[devtype->cs_regs_count];
int i, ret;
@@ -128,13 +128,13 @@ static int weim_parse_dt(struct imx_weim *weim)
static int weim_probe(struct device *dev)
{
struct resource *iores;
- struct imx_weim_devtype *devtype;
+ const struct imx_weim_devtype *devtype;
struct imx_weim *weim;
int ret;
- ret = dev_get_drvdata(dev, (const void **)&devtype);
- if (ret)
- return ret;
+ devtype = device_get_match_data(dev);
+ if (!devtype)
+ return -ENODEV;
weim = xzalloc(sizeof(*weim));
diff --git a/drivers/clocksource/timer-imx-gpt.c b/drivers/clocksource/timer-imx-gpt.c
index 6cf60ed3fc28..5d0d8616f14e 100644
--- a/drivers/clocksource/timer-imx-gpt.c
+++ b/drivers/clocksource/timer-imx-gpt.c
@@ -52,7 +52,7 @@ static struct imx_gpt_regs regs_imx31 = {
.tctl_val = IMX31_TCTL_FRR | IMX31_TCTL_CLKSOURCE_PER | TCTL_TEN,
};
-static struct imx_gpt_regs *regs;
+static const struct imx_gpt_regs *regs;
static void __iomem *timer_base;
static uint64_t imx_clocksource_read(void)
@@ -81,16 +81,15 @@ static int imx_gpt_probe(struct device *dev)
{
struct resource *iores;
int i;
- int ret;
unsigned long rate;
/* one timer is enough */
if (timer_base)
return 0;
- ret = dev_get_drvdata(dev, (const void **)®s);
- if (ret)
- return ret;
+ regs = device_get_match_data(dev);
+ if (!regs)
+ return -ENODEV;
iores = dev_request_mem_resource(dev, 0);
if (IS_ERR(iores))
diff --git a/drivers/eeprom/at24.c b/drivers/eeprom/at24.c
index 23cb0e1fbbc9..3054709ec055 100644
--- a/drivers/eeprom/at24.c
+++ b/drivers/eeprom/at24.c
@@ -380,9 +380,9 @@ static int at24_probe(struct device *dev)
unsigned long magic;
u32 page_size;
- err = dev_get_drvdata(dev, (const void **)&magic);
- if (err)
- return err;
+ magic = (uintptr_t)device_get_match_data(dev);
+ if (!magic)
+ return -ENODEV;
chip.byte_len = BIT(magic & AT24_BITMASK(AT24_SIZE_BYTELEN));
magic >>= AT24_SIZE_BYTELEN;
diff --git a/drivers/firmware/altera_serial.c b/drivers/firmware/altera_serial.c
index 8ff46753e44b..66ef70b8a949 100644
--- a/drivers/firmware/altera_serial.c
+++ b/drivers/firmware/altera_serial.c
@@ -340,9 +340,9 @@ static int altera_spi_probe(struct device *dev)
dev_dbg(dev, "Probing FPGA firmware programmer\n");
- rc = dev_get_drvdata(dev, (const void **)&data);
- if (rc)
- return rc;
+ data = device_get_match_data(dev);
+ if (!data)
+ return -ENODEV;
this = xzalloc(sizeof(*this));
fh = &this->fh;
diff --git a/drivers/gpio/gpio-imx.c b/drivers/gpio/gpio-imx.c
index 49c5555b9859..d9499c66cdae 100644
--- a/drivers/gpio/gpio-imx.c
+++ b/drivers/gpio/gpio-imx.c
@@ -17,7 +17,7 @@
struct imx_gpio_chip {
void __iomem *base;
struct gpio_chip chip;
- struct imx_gpio_regs *regs;
+ const struct imx_gpio_regs *regs;
};
struct imx_gpio_regs {
@@ -121,12 +121,11 @@ static int imx_gpio_probe(struct device *dev)
{
struct resource *iores;
struct imx_gpio_chip *imxgpio;
- struct imx_gpio_regs *regs;
- int ret;
+ const struct imx_gpio_regs *regs;
- ret = dev_get_drvdata(dev, (const void **)®s);
- if (ret)
- return ret;
+ regs = device_get_match_data(dev);
+ if (!regs)
+ return -ENODEV;
imxgpio = xzalloc(sizeof(*imxgpio));
iores = dev_request_mem_resource(dev, 0);
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index 3fcb7387e30c..ed043286b7ff 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -119,9 +119,9 @@ static int omap_gpio_probe(struct device *dev)
{
struct resource *iores;
struct omap_gpio_chip *omapgpio;
- struct omap_gpio_drvdata *drvdata = NULL;
+ const struct omap_gpio_drvdata *drvdata;
- dev_get_drvdata(dev, (const void **)&drvdata);
+ drvdata = device_get_match_data(dev);
omapgpio = xzalloc(sizeof(*omapgpio));
iores = dev_request_mem_resource(dev, 0);
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index e303f6b21f4b..4dd0c43afc32 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -432,11 +432,9 @@ static int pca953x_probe(struct device *dev)
invert = pdata->invert;
chip->names = pdata->names;
} else {
- int err;
-
- err = dev_get_drvdata(dev, (const void **)&driver_data);
- if (err)
- return err;
+ driver_data = (uintptr_t)device_get_match_data(dev);
+ if (!driver_data)
+ return -ENODEV;
chip->gpio_start = -1;
}
diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c
index 52c3a6d00ac1..1db2eea47afe 100644
--- a/drivers/gpio/gpio-pcf857x.c
+++ b/drivers/gpio/gpio-pcf857x.c
@@ -152,7 +152,6 @@ static int pcf857x_probe(struct device *dev)
struct pcf857x *gpio;
unsigned long driver_data;
unsigned int n_latch = 0;
- int ret;
if (!np)
return -EINVAL;
@@ -162,9 +161,9 @@ static int pcf857x_probe(struct device *dev)
/* Allocate, initialize, and register this gpio_chip. */
gpio = xzalloc(sizeof(*gpio));
- ret = dev_get_drvdata(dev, (const void **)&driver_data);
- if (ret)
- return ret;
+ driver_data = (ulong)device_get_match_data(dev);
+ if (!driver_data)
+ return -ENODEV;
gpio->chip.base = -1;
gpio->chip.ops = &pcf857x_gpio_ops;
diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index 693432a8c9c6..fb52041c361f 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -32,7 +32,7 @@ struct tegra_gpio_soc_config {
};
static void __iomem *gpio_base;
-static struct tegra_gpio_soc_config *config;
+static const struct tegra_gpio_soc_config *config;
static inline void tegra_gpio_writel(u32 val, u32 reg)
{
@@ -128,13 +128,11 @@ static struct gpio_chip tegra_gpio_chip = {
static int tegra_gpio_probe(struct device *dev)
{
struct resource *iores;
- int i, j, ret;
+ int i, j;
- ret = dev_get_drvdata(dev, (const void **)&config);
- if (ret) {
- dev_err(dev, "dev_get_drvdata failed: %d\n", ret);
- return ret;
- }
+ config = device_get_match_data(dev);
+ if (!config)
+ return -ENODEV;
iores = dev_request_mem_resource(dev, 0);
if (IS_ERR(iores)) {
diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index 7c535c2e5eff..eefbaa70230f 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -157,11 +157,11 @@ static int vf610_gpio_probe(struct device *dev)
struct resource *iores;
struct vf610_gpio_port *port;
const __be32 *gpio_ranges;
- struct fsl_gpio_soc_data *devtype;
+ const struct fsl_gpio_soc_data *devtype;
- ret = dev_get_drvdata(dev, (const void **)&devtype);
- if (ret)
- return ret;
+ devtype = device_get_match_data(dev);
+ if (!devtype)
+ return -ENODEV;
port = xzalloc(sizeof(*port));
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index 8929dbaedebc..75113706f8ad 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -91,7 +91,7 @@ struct at91_twi_dev {
unsigned transfer_status;
struct i2c_adapter adapter;
unsigned twi_cwgr_reg;
- struct at91_twi_pdata *pdata;
+ const struct at91_twi_pdata *pdata;
u32 filter_width;
bool enable_dig_filt;
@@ -118,7 +118,7 @@ static void at91_disable_twi_interrupts(struct at91_twi_dev *dev)
static void at91_init_twi_bus(struct at91_twi_dev *dev)
{
- struct at91_twi_pdata *pdata = dev->pdata;
+ const struct at91_twi_pdata *pdata = dev->pdata;
u32 filtr = 0;
at91_disable_twi_interrupts(dev);
@@ -152,7 +152,7 @@ static void at91_init_twi_bus(struct at91_twi_dev *dev)
static void at91_calc_twi_clock(struct at91_twi_dev *dev, int twi_clk)
{
int ckdiv, cdiv, div, hold = 0, filter_width = 0;
- struct at91_twi_pdata *pdata = dev->pdata;
+ const struct at91_twi_pdata *pdata = dev->pdata;
int offset = pdata->clk_offset;
int max_ckdiv = pdata->clk_max_div;
struct i2c_timings timings, *t = &timings;
@@ -517,19 +517,17 @@ static int at91_twi_probe(struct device *dev)
{
struct resource *iores;
struct at91_twi_dev *i2c_at91;
- struct at91_twi_pdata *i2c_data;
+ const struct at91_twi_pdata *i2c_data;
int rc = 0;
u32 bus_clk_rate;
+ i2c_data = device_get_match_data(dev);
+ if (!i2c_data)
+ return -ENODEV;
+
i2c_at91 = xzalloc(sizeof(struct at91_twi_dev));
i2c_at91->dev = dev;
- rc = dev_get_drvdata(dev, (const void **)&i2c_data);
- if (rc < 0) {
- dev_err(dev, "failed to retrieve driver data\n");
- goto out_free;
- }
-
i2c_at91->pdata = i2c_data;
iores = dev_request_mem_resource(dev, 0);
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index 6629e65b48b4..69fbfdcadba0 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -535,7 +535,7 @@ mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data,
u32 bus_freq, tclk;
int rc = 0;
u32 prop;
- struct mv64xxx_i2c_regs *mv64xxx_regs;
+ const struct mv64xxx_i2c_regs *mv64xxx_regs;
int freq;
if (IS_ERR(drv_data->clk)) {
@@ -577,7 +577,7 @@ mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data,
goto out;
}
- dev_get_drvdata(pd, (const void **)&mv64xxx_regs);
+ mv64xxx_regs = device_get_match_data(pd);
memcpy(&drv_data->reg_offsets, mv64xxx_regs,
sizeof(drv_data->reg_offsets));
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index a1a6cefd60bd..29378a96d722 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -144,7 +144,7 @@
struct omap_i2c_struct {
void *base;
u8 reg_shift;
- struct omap_i2c_driver_data *data;
+ const struct omap_i2c_driver_data *data;
struct resource *ioarea;
u32 speed; /* Speed of bus in Khz */
u16 scheme;
@@ -345,7 +345,7 @@ static int omap_i2c_init(struct omap_i2c_struct *i2c_omap)
u16 fsscll = 0, fssclh = 0, hsscll = 0, hssclh = 0;
uint64_t start;
unsigned long internal_clk = 0;
- struct omap_i2c_driver_data *i2c_data = i2c_omap->data;
+ const struct omap_i2c_driver_data *i2c_data = i2c_omap->data;
if (i2c_omap->rev >= OMAP_I2C_OMAP1_REV_2) {
/* Disable I2C controller before soft reset */
@@ -1063,7 +1063,7 @@ i2c_omap_probe(struct device *pdev)
{
struct resource *iores;
struct omap_i2c_struct *i2c_omap;
- struct omap_i2c_driver_data *i2c_data;
+ const struct omap_i2c_driver_data *i2c_data;
int r;
u32 speed = 0;
u32 rev;
@@ -1075,9 +1075,9 @@ i2c_omap_probe(struct device *pdev)
goto err_free_mem;
}
- r = dev_get_drvdata(pdev, (const void **)&i2c_data);
- if (r)
- return r;
+ i2c_data = device_get_match_data(pdev);
+ if (!i2c_data)
+ return -ENODEV;
if (of_machine_is_compatible("ti,am33xx"))
i2c_data = &am33xx_data;
diff --git a/drivers/i2c/busses/i2c-stm32.c b/drivers/i2c/busses/i2c-stm32.c
index 4d40ca3b51cc..d9a51c6108cf 100644
--- a/drivers/i2c/busses/i2c-stm32.c
+++ b/drivers/i2c/busses/i2c-stm32.c
@@ -867,9 +867,9 @@ static int stm32_of_to_plat(struct device *dev, struct stm32_i2c_priv *i2c_priv)
const struct stm32_i2c_data *data;
int ret;
- ret = dev_get_drvdata(dev, (const void **)&data);
- if (ret)
- return ret;
+ data = device_get_match_data(dev);
+ if (!data)
+ return -ENODEV;
if (of_property_read_u32(dev->of_node, "i2c-digital-filter-width-ns",
&i2c_priv->setup.timings.digital_filter_width_ns))
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 4271a22f8326..c4506170f375 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -632,8 +632,10 @@ static int tegra_i2c_probe(struct device *dev)
if (ret)
i2c_dev->bus_clk_rate = 100000; /* default clock rate */
- i2c_dev->hw = &tegra20_i2c_hw;
- dev_get_drvdata(dev, (const void **)&i2c_dev->hw);
+ i2c_dev->hw = device_get_match_data(dev);
+ if (!i2c_dev->hw)
+ i2c_dev->hw = &tegra20_i2c_hw;
+
i2c_dev->is_dvc = of_device_is_compatible(dev->of_node,
"nvidia,tegra20-i2c-dvc");
diff --git a/drivers/mailbox/ti-msgmgr.c b/drivers/mailbox/ti-msgmgr.c
index 58ec8697fcdf..81dc1358ca5f 100644
--- a/drivers/mailbox/ti-msgmgr.c
+++ b/drivers/mailbox/ti-msgmgr.c
@@ -340,9 +340,9 @@ static int k3_sec_proxy_probe(struct device *dev)
spm->rt = IOMEM(res->start);
- ret = dev_get_drvdata(dev, &data);
- if (ret)
- return ret;
+ data = device_get_match_data(dev);
+ if (!data)
+ return -ENODEV;
spm->desc = data;
spm->k3_chans = xzalloc(spm->desc->num_valid_threads * sizeof(*spm->k3_chans));
diff --git a/drivers/mci/am654-sdhci.c b/drivers/mci/am654-sdhci.c
index 2c1fa5d80451..b4735952515f 100644
--- a/drivers/mci/am654-sdhci.c
+++ b/drivers/mci/am654-sdhci.c
@@ -554,9 +554,9 @@ static int am654_sdhci_probe(struct device *dev)
plat = xzalloc(sizeof(*plat));
- ret = dev_get_drvdata(dev, (const void **)&plat->soc_data);
- if (ret)
- return ret;
+ plat->soc_data = device_get_match_data(dev);
+ if (!plat->soc_data)
+ return -ENODEV;
iores = dev_request_mem_resource(dev, 0);
if (IS_ERR(iores))
diff --git a/drivers/mci/imx-esdhc.c b/drivers/mci/imx-esdhc.c
index ebc7ed539da9..519bb86a6a2e 100644
--- a/drivers/mci/imx-esdhc.c
+++ b/drivers/mci/imx-esdhc.c
@@ -283,9 +283,9 @@ static int fsl_esdhc_probe(struct device *dev)
unsigned long rate;
const struct esdhc_soc_data *socdata;
- ret = dev_get_drvdata(dev, (const void **)&socdata);
- if (ret)
- return ret;
+ socdata = device_get_match_data(dev);
+ if (!socdata)
+ return -ENODEV;
host = xzalloc(sizeof(*host));
host->socdata = socdata;
diff --git a/drivers/mci/omap_hsmmc.c b/drivers/mci/omap_hsmmc.c
index 616d57bffdac..9101b4c30a2c 100644
--- a/drivers/mci/omap_hsmmc.c
+++ b/drivers/mci/omap_hsmmc.c
@@ -80,12 +80,11 @@ static int omap_mmc_probe(struct device *dev)
struct resource *iores;
struct omap_hsmmc *hsmmc;
struct omap_hsmmc_platform_data *pdata;
- struct omap_mmc_driver_data *drvdata;
+ const struct omap_mmc_driver_data *drvdata;
unsigned long reg_ofs = 0;
- int ret;
- ret = dev_get_drvdata(dev, (const void **)&drvdata);
- if (!ret)
+ drvdata = device_get_match_data(dev);
+ if (drvdata)
reg_ofs = drvdata->reg_ofs;
hsmmc = xzalloc(sizeof(*hsmmc));
diff --git a/drivers/mfd/mc13xxx.c b/drivers/mfd/mc13xxx.c
index 5dabfe3f6115..288bd407ff10 100644
--- a/drivers/mfd/mc13xxx.c
+++ b/drivers/mfd/mc13xxx.c
@@ -302,15 +302,15 @@ static const struct regmap_config mc13xxx_regmap_i2c_config = {
static int __init mc13xxx_probe(struct device *dev)
{
- struct mc13xxx_devtype *devtype;
+ const struct mc13xxx_devtype *devtype;
int ret, rev;
if (mc_dev)
return -EBUSY;
- ret = dev_get_drvdata(dev, (const void **)&devtype);
- if (ret)
- return ret;
+ devtype = device_get_match_data(dev);
+ if (!devtype)
+ return -ENODEV;
mc_dev = xzalloc(sizeof(*mc_dev));
mc_dev->dev = dev;
diff --git a/drivers/mtd/nand/raw/mxc_nand.c b/drivers/mtd/nand/raw/mxc_nand.c
index 1aba9afdd1fa..de2ad2a028cb 100644
--- a/drivers/mtd/nand/raw/mxc_nand.c
+++ b/drivers/mtd/nand/raw/mxc_nand.c
@@ -1778,12 +1778,12 @@ static int mxcnd_probe(struct device *dev)
struct mtd_info *mtd;
struct mxc_nand_host *host;
struct resource *iores;
- struct mxc_nand_devtype_data* devtype;
+ const struct mxc_nand_devtype_data* devtype;
int err = 0;
- err = dev_get_drvdata(dev, (const void **)&devtype);
- if (err)
- return err;
+ devtype = device_get_match_data(dev);
+ if (!devtype)
+ return -ENODEV;
/* Allocate memory for MTD device structure and private data */
host = devm_kzalloc(dev, sizeof(struct mxc_nand_host),
diff --git a/drivers/mtd/nand/raw/nand_denali_dt.c b/drivers/mtd/nand/raw/nand_denali_dt.c
index d21cdc975612..d6546550a30e 100644
--- a/drivers/mtd/nand/raw/nand_denali_dt.c
+++ b/drivers/mtd/nand/raw/nand_denali_dt.c
@@ -176,16 +176,16 @@ static int denali_dt_probe(struct device *ofdev)
struct resource *iores;
struct denali_dt *dt;
struct denali_controller *denali;
- struct denali_dt_data *data;
+ const struct denali_dt_data *data;
struct device_node *np;
int ret;
if (!IS_ENABLED(CONFIG_OFDEVICE))
return 1;
- ret = dev_get_drvdata(ofdev, (const void **)&data);
- if (ret)
- return ret;
+ data = device_get_match_data(ofdev);
+ if (!data)
+ return -ENODEV;
dt = kzalloc(sizeof(*dt), GFP_KERNEL);
if (!dt)
diff --git a/drivers/net/ag71xx.c b/drivers/net/ag71xx.c
index 2bce142de328..62b299dd900d 100644
--- a/drivers/net/ag71xx.c
+++ b/drivers/net/ag71xx.c
@@ -552,15 +552,14 @@ static int ag71xx_probe(struct device *dev)
void __iomem *regs, *regs_gmac;
struct mii_bus *miibus;
struct eth_device *edev;
- struct ag71xx_cfg *cfg;
+ const struct ag71xx_cfg *cfg;
struct ag71xx *priv;
u32 mac_h, mac_l;
u32 rd, mask;
- int ret;
- ret = dev_get_drvdata(dev, (const void **)&cfg);
- if (ret)
- return ret;
+ cfg = device_get_match_data(dev);
+ if (!cfg)
+ return -ENODEV;
regs_gmac = dev_request_mem_region_by_name(dev, "gmac");
if (IS_ERR(regs_gmac))
diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index 6c30fdc2a631..6b6d914d7bf9 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -448,22 +448,18 @@ struct dw_eth_dev *dwc_drv_probe(struct device *dev)
void __iomem *base;
struct dwc_ether_platform_data *pdata = dev->platform_data;
int ret;
- struct dw_eth_drvdata *drvdata;
+ const struct dw_eth_drvdata *drvdata;
dma_set_mask(dev, DMA_BIT_MASK(32));
priv = xzalloc(sizeof(struct dw_eth_dev));
- ret = dev_get_drvdata(dev, (const void **)&drvdata);
- if (ret)
- return ERR_PTR(ret);
+ drvdata = device_get_match_data(dev);
+ if (!drvdata)
+ return ERR_PTR(-ENODEV);
- if (drvdata) {
- priv->enh_desc = drvdata->enh_desc;
- priv->fix_mac_speed = drvdata->fix_mac_speed;
- } else {
- dev_warn(dev, "No drvdata specified\n");
- }
+ priv->enh_desc = drvdata->enh_desc;
+ priv->fix_mac_speed = drvdata->fix_mac_speed;
if (pdata) {
priv->phy_addr = pdata->phy_addr;
diff --git a/drivers/net/designware_imx.c b/drivers/net/designware_imx.c
index 77e987e9ac80..ec3558fad026 100644
--- a/drivers/net/designware_imx.c
+++ b/drivers/net/designware_imx.c
@@ -39,7 +39,7 @@ struct eqos_imx_priv {
struct regmap *intf_regmap;
u32 intf_reg_off;
bool rmii_refclk_ext;
- struct eqos_imx_soc_data *soc_data;
+ const struct eqos_imx_soc_data *soc_data;
};
enum { CLK_STMMACETH, CLK_PCLK, CLK_PTP_REF, CLK_TX};
@@ -212,13 +212,13 @@ static struct eqos_ops imx_ops = {
static int eqos_probe_imx(struct device *dev)
{
struct device_node *np = dev->device_node;
- struct eqos_imx_soc_data *soc_data;
+ const struct eqos_imx_soc_data *soc_data;
struct eqos_imx_priv *priv;
int ret;
- ret = dev_get_drvdata(dev, (const void **)&soc_data);
- if (ret)
- return ret;
+ soc_data = device_get_match_data(dev);
+ if (!soc_data)
+ return -ENODEV;
priv = xzalloc(sizeof(*priv));
diff --git a/drivers/net/designware_socfpga.c b/drivers/net/designware_socfpga.c
index a39c945c8191..dd17b291a193 100644
--- a/drivers/net/designware_socfpga.c
+++ b/drivers/net/designware_socfpga.c
@@ -191,17 +191,14 @@ static int socfpga_dwc_ether_probe(struct device *dev)
{
struct socfpga_dwc_dev *dwc_dev;
struct dw_eth_dev *priv;
- struct dw_eth_drvdata *drvdata;
+ const struct dw_eth_drvdata *drvdata;
int ret;
dwc_dev = xzalloc(sizeof(*dwc_dev));
- ret = dev_get_drvdata(dev, (const void **)&drvdata);
- if (ret)
- return ret;
-
+ drvdata = device_get_match_data(dev);
if (drvdata && drvdata->priv)
- dwc_dev->ops = (struct socfpga_dwmac_ops *)drvdata->priv;
+ dwc_dev->ops = drvdata->priv;
else
return -EINVAL;
diff --git a/drivers/net/fec_imx.c b/drivers/net/fec_imx.c
index 0598b09704f9..8474e6d5be9c 100644
--- a/drivers/net/fec_imx.c
+++ b/drivers/net/fec_imx.c
@@ -769,9 +769,9 @@ static int fec_probe(struct device *dev)
u32 msec = 1, phy_post_delay = 0;
u32 reg;
- ret = dev_get_drvdata(dev, &type_v);
- if (ret)
- return ret;
+ type_v = device_get_match_data(dev);
+ if (!type_v)
+ return -ENODEV;
type = (uintptr_t)(type_v);
diff --git a/drivers/net/fsl-fman.c b/drivers/net/fsl-fman.c
index f205de1929ea..84e7f2033037 100644
--- a/drivers/net/fsl-fman.c
+++ b/drivers/net/fsl-fman.c
@@ -1085,15 +1085,14 @@ static int fsl_fman_mdio_probe(struct device *dev)
static int fsl_fman_port_probe(struct device *dev)
{
struct resource *iores;
- int ret;
struct fsl_fman_port *port;
unsigned long type;
dev_dbg(dev, "probe\n");
- ret = dev_get_drvdata(dev, (const void **)&type);
- if (ret)
- return ret;
+ type = (uintptr_t)device_get_match_data(dev);
+ if (!type)
+ return -ENODEV;
iores = dev_request_mem_resource(dev, 0);
if (IS_ERR(iores))
diff --git a/drivers/nvmem/bsec.c b/drivers/nvmem/bsec.c
index edaf577e9823..9ca98e6180f8 100644
--- a/drivers/nvmem/bsec.c
+++ b/drivers/nvmem/bsec.c
@@ -204,9 +204,9 @@ static int stm32_bsec_probe(struct device *dev)
const struct stm32_bsec_data *data;
struct nvmem_device *nvmem;
- ret = dev_get_drvdata(dev, (const void **)&data);
- if (ret)
- return ret;
+ data = device_get_match_data(dev);
+ if (!data)
+ return -ENODEV;
priv = xzalloc(sizeof(*priv));
diff --git a/drivers/nvmem/imx-ocotp-ele.c b/drivers/nvmem/imx-ocotp-ele.c
index 58d3e62abfdb..5fb5dfc87e22 100644
--- a/drivers/nvmem/imx-ocotp-ele.c
+++ b/drivers/nvmem/imx-ocotp-ele.c
@@ -163,15 +163,14 @@ static int imx_ele_ocotp_probe(struct device *dev)
struct imx_ocotp_priv *priv;
struct nvmem_device *nvmem;
struct resource *iores;
- struct ocotp_devtype_data *data;
- int ret;
+ const struct ocotp_devtype_data *data;
priv = xzalloc(sizeof(*priv));
priv->dev = dev;
- ret = dev_get_drvdata(dev, (const void **)&data);
- if (ret)
- return ret;
+ data = device_get_match_data(dev);
+ if (!data)
+ return -ENODEV;
iores = dev_request_mem_resource(dev, 0);
if (IS_ERR(iores))
diff --git a/drivers/nvmem/ocotp.c b/drivers/nvmem/ocotp.c
index 87cc95a636f3..5d4737767866 100644
--- a/drivers/nvmem/ocotp.c
+++ b/drivers/nvmem/ocotp.c
@@ -868,9 +868,9 @@ static int imx_ocotp_probe(struct device *dev)
const struct imx_ocotp_data *data;
struct nvmem_device *nvmem;
- ret = dev_get_drvdata(dev, (const void **)&data);
- if (ret)
- return ret;
+ data = device_get_match_data(dev);
+ if (!data)
+ return -ENODEV;
iores = dev_request_mem_resource(dev, 0);
if (IS_ERR(iores))
diff --git a/drivers/pci/pci-tegra.c b/drivers/pci/pci-tegra.c
index 9ef50207ab35..b7f8297d153e 100644
--- a/drivers/pci/pci-tegra.c
+++ b/drivers/pci/pci-tegra.c
@@ -1245,7 +1245,7 @@ static int tegra_pcie_probe(struct device *dev)
INIT_LIST_HEAD(&pcie->buses);
INIT_LIST_HEAD(&pcie->ports);
- dev_get_drvdata(dev, (const void **)&pcie->soc_data);
+ pcie->soc_data = device_get_match_data(dev);
pcie->dev = dev;
err = tegra_pcie_parse_dt(pcie);
diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c
index ddc725187bf0..25b4d084ed6d 100644
--- a/drivers/pinctrl/pinctrl-at91.c
+++ b/drivers/pinctrl/pinctrl-at91.c
@@ -646,11 +646,9 @@ static int at91_gpio_probe(struct device *dev)
at91_gpio = &gpio_chip[alias_idx];
- ret = dev_get_drvdata(dev, (const void **)&at91_gpio->ops);
- if (ret) {
- dev_err(dev, "dev_get_drvdata failed: %d\n", ret);
- return ret;
- }
+ at91_gpio->ops = device_get_match_data(dev);
+ if (!at91_gpio->ops)
+ return -ENODEV;
clk = clk_get(dev, NULL);
if (IS_ERR(clk)) {
diff --git a/drivers/power/reset/syscon-reboot-mode.c b/drivers/power/reset/syscon-reboot-mode.c
index 00b2f77146d2..20ab71febdcb 100644
--- a/drivers/power/reset/syscon-reboot-mode.c
+++ b/drivers/power/reset/syscon-reboot-mode.c
@@ -50,7 +50,7 @@ static int syscon_reboot_mode_probe(struct device *dev)
{
int ret, i, nelems;
struct syscon_reboot_mode *syscon_rbm;
- struct reboot_mode_driver *reboot_template;
+ const struct reboot_mode_driver *reboot_template;
struct device_node *np = dev->of_node;
u32 *magic;
@@ -60,9 +60,9 @@ static int syscon_reboot_mode_probe(struct device *dev)
syscon_rbm = xzalloc(struct_size(syscon_rbm, reg, nelems));
- ret = dev_get_drvdata(dev, (const void **)&reboot_template);
- if (ret)
- return ret;
+ reboot_template = device_get_match_data(dev);
+ if (!reboot_template)
+ return -ENODEV;
syscon_rbm->reboot = *reboot_template;
syscon_rbm->reboot.dev = dev;
diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index 851676c0dd87..a847d4d434e3 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -425,9 +425,9 @@ static int atmel_pwm_probe(struct device *dev)
int ret;
int i;
- ret = dev_get_drvdata(dev, (const void **)&data);
- if (ret)
- return ret;
+ data = device_get_match_data(dev);
+ if (!data)
+ return -ENODEV;
atmel_pwm = xzalloc(sizeof(*atmel_pwm));
atmel_pwm->data = data;
diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c
index 2a754005939c..64fd6c190d21 100644
--- a/drivers/pwm/pwm-imx.c
+++ b/drivers/pwm/pwm-imx.c
@@ -248,11 +248,10 @@ static int imx_pwm_probe(struct device *dev)
struct resource *iores;
const struct imx_pwm_data *data;
struct imx_chip *imx;
- int ret;
- ret = dev_get_drvdata(dev, (const void **)&data);
- if (ret)
- return ret;
+ data = device_get_match_data(dev);
+ if (!data)
+ return -ENODEV;
imx = xzalloc(sizeof(*imx));
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index e1a8e214d2b0..86b0709dc217 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -290,11 +290,11 @@ static int ds1307_probe(struct device *dev)
unsigned long driver_data;
const struct device_node *np = dev->of_node;
- ds1307 = xzalloc(sizeof(struct ds1307));
+ driver_data = (uintptr_t)device_get_match_data(dev);
+ if (!driver_data)
+ return -ENODEV;
- err = dev_get_drvdata(dev, (const void **)&driver_data);
- if (err)
- goto exit;
+ ds1307 = xzalloc(sizeof(struct ds1307));
ds1307->client = client;
ds1307->type = driver_data;
diff --git a/drivers/serial/serial_cadence.c b/drivers/serial/serial_cadence.c
index fe05d8a44d52..bda3269106c7 100644
--- a/drivers/serial/serial_cadence.c
+++ b/drivers/serial/serial_cadence.c
@@ -32,7 +32,7 @@ struct cadence_serial_priv {
struct notifier_block notify;
void __iomem *regs;
struct clk *clk;
- struct cadence_serial_devtype_data *devtype;
+ const struct cadence_serial_devtype_data *devtype;
};
static int cadence_serial_reset(struct console_device *cdev)
@@ -178,12 +178,12 @@ static int cadence_serial_probe(struct device *dev)
struct resource *iores;
struct console_device *cdev;
struct cadence_serial_priv *priv;
- struct cadence_serial_devtype_data *devtype;
+ const struct cadence_serial_devtype_data *devtype;
int ret;
- ret = dev_get_drvdata(dev, (const void **)&devtype);
- if (ret)
- return ret;
+ devtype = device_get_match_data(dev);
+ if (!devtype)
+ return -ENODEV;
priv = xzalloc(sizeof(*priv));
priv->devtype = devtype;
diff --git a/drivers/serial/serial_imx.c b/drivers/serial/serial_imx.c
index 77eea78aba64..e13b69f2cf0e 100644
--- a/drivers/serial/serial_imx.c
+++ b/drivers/serial/serial_imx.c
@@ -48,7 +48,7 @@ struct imx_serial_priv {
struct notifier_block notify;
void __iomem *regs;
struct clk *clk;
- struct imx_serial_devtype_data *devtype;
+ const struct imx_serial_devtype_data *devtype;
bool rs485_mode;
};
@@ -203,13 +203,13 @@ static int imx_serial_probe(struct device *dev)
struct console_device *cdev;
struct imx_serial_priv *priv;
uint32_t val;
- struct imx_serial_devtype_data *devtype;
+ const struct imx_serial_devtype_data *devtype;
int ret;
const char *devname;
- ret = dev_get_drvdata(dev, (const void **)&devtype);
- if (ret)
- return ret;
+ devtype = device_get_match_data(dev);
+ if (!devtype)
+ return -ENODEV;
priv = xzalloc(sizeof(*priv));
priv->devtype = devtype;
diff --git a/drivers/serial/serial_lpuart32.c b/drivers/serial/serial_lpuart32.c
index 6b52882bf0bd..25f0782e026e 100644
--- a/drivers/serial/serial_lpuart32.c
+++ b/drivers/serial/serial_lpuart32.c
@@ -102,11 +102,11 @@ static int lpuart32_serial_probe(struct device *dev)
struct console_device *cdev;
struct lpuart32 *lpuart32;
const char *devname;
- struct lpuart32_devtype_data *devtype;
+ const struct lpuart32_devtype_data *devtype;
- ret = dev_get_drvdata(dev, (const void **)&devtype);
- if (ret)
- return ret;
+ devtype = device_get_match_data(dev);
+ if (!devtype)
+ return -ENODEV;
lpuart32 = xzalloc(sizeof(*lpuart32));
cdev = &lpuart32->cdev;
diff --git a/drivers/serial/serial_stm32.c b/drivers/serial/serial_stm32.c
index eebae6f6ee9e..f61d04aed440 100644
--- a/drivers/serial/serial_stm32.c
+++ b/drivers/serial/serial_stm32.c
@@ -145,11 +145,11 @@ static int stm32_serial_probe(struct device *dev)
struct stm32_uart *stm32;
const char *devname;
struct resource *res;
- struct stm32_uart_info *info;
+ const struct stm32_uart_info *info;
- ret = dev_get_drvdata(dev, (const void **)&info);
- if (ret)
- return ret;
+ info = device_get_match_data(dev);
+ if (!info)
+ return -ENODEV;
stm32 = xzalloc(sizeof(*stm32));
cdev = &stm32->cdev;
diff --git a/drivers/spi/imx_spi.c b/drivers/spi/imx_spi.c
index 09893ac008e8..bfb4b413ebab 100644
--- a/drivers/spi/imx_spi.c
+++ b/drivers/spi/imx_spi.c
@@ -583,11 +583,11 @@ static int imx_spi_probe(struct device *dev)
struct spi_master *master;
struct imx_spi *imx;
struct spi_imx_master *pdata = dev->platform_data;
- struct spi_imx_devtype_data *devdata = NULL;
+ const struct spi_imx_devtype_data *devdata;
int ret;
- ret = dev_get_drvdata(dev, (const void **)&devdata);
- if (ret)
+ devdata = device_get_match_data(dev);
+ if (!devdata)
return -ENODEV;
imx = xzalloc(sizeof(*imx));
diff --git a/drivers/spi/omap3_spi.c b/drivers/spi/omap3_spi.c
index 78c3a8233830..d34f505ec993 100644
--- a/drivers/spi/omap3_spi.c
+++ b/drivers/spi/omap3_spi.c
@@ -349,12 +349,11 @@ static int omap3_spi_probe(struct device *dev)
struct resource *iores;
struct spi_master *master;
struct omap3_spi_master *omap3_master;
- struct omap_spi_drvdata *devtype;
- int ret;
+ const struct omap_spi_drvdata *devtype;
- ret = dev_get_drvdata(dev, (const void **)&devtype);
- if (ret)
- return ret;
+ devtype = device_get_match_data(dev);
+ if (!devtype)
+ return -ENODEV;
omap3_master = xzalloc(sizeof(*omap3_master));
diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index f032e2673eb6..8018643bd7c3 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -585,8 +585,8 @@ static int dspi_probe(struct device *dev)
of_property_read_u32(np, "bus-num", &bus_num);
master->bus_num = bus_num;
- ret = dev_get_drvdata(dev, (const void **)&dspi->devtype_data);
- if (ret)
+ dspi->devtype_data = device_get_match_data(dev);
+ if (!dspi->devtype_data)
return -ENODEV;
res = dev_request_mem_resource(dev, 0);
diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index 94fbb9f0ed2c..e09857f23c27 100644
--- a/drivers/usb/imx/chipidea-imx.c
+++ b/drivers/usb/imx/chipidea-imx.c
@@ -217,7 +217,7 @@ static int ci_set_mode(void *ctx, enum usb_dr_mode mode)
static int imx_chipidea_probe(struct device *dev)
{
struct resource *iores;
- struct imx_chipidea_data *imx_data;
+ const struct imx_chipidea_data *imx_data;
struct imxusb_platformdata *pdata = dev->platform_data;
char const *phynode_name;
int ret;
@@ -229,8 +229,8 @@ static int imx_chipidea_probe(struct device *dev)
ci->dev = dev;
dev->priv = ci;
- ret = dev_get_drvdata(dev, (const void **)&imx_data);
- if (!ret)
+ imx_data = device_get_match_data(dev);
+ if (imx_data)
ci->have_usb_misc = imx_data->have_usb_misc;
if (IS_ENABLED(CONFIG_OFDEVICE) && dev->of_node) {
diff --git a/drivers/usb/imx/imx-usb-misc.c b/drivers/usb/imx/imx-usb-misc.c
index bf9583e62645..2553095e29fd 100644
--- a/drivers/usb/imx/imx-usb-misc.c
+++ b/drivers/usb/imx/imx-usb-misc.c
@@ -35,7 +35,7 @@ struct imx_usb_misc_data {
};
struct imx_usb_misc_priv {
- struct imx_usb_misc_data *data;
+ const struct imx_usb_misc_data *data;
void __iomem *base;
};
@@ -653,13 +653,12 @@ int imx_usbmisc_port_post_init(struct device *dev, int port, unsigned flags)
static int imx_usbmisc_probe(struct device *dev)
{
struct resource *iores;
- struct imx_usb_misc_data *devtype;
+ const struct imx_usb_misc_data *devtype;
struct imx_usb_misc_priv *usbmisc;
- int ret;
- ret = dev_get_drvdata(dev, (const void **)&devtype);
- if (ret)
- return ret;
+ devtype = device_get_match_data(dev);
+ if (!devtype)
+ return -ENODEV;
iores = dev_request_mem_resource(dev, 0);
if (IS_ERR(iores))
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index 97b64302eccf..914212498c79 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -309,9 +309,9 @@ static int dsps_probe(struct device *dev)
struct dsps_glue *glue;
int ret;
- ret = dev_get_drvdata(dev, (const void **)&wrp);
- if (ret)
- return ret;
+ wrp = device_get_match_data(dev);
+ if (!wrp)
+ return -ENODEV;
if (!IS_ENABLED(CONFIG_USB_MUSB_HOST) &&
!IS_ENABLED(CONFIG_USB_MUSB_GADGET)) {
diff --git a/drivers/usb/musb/phy-am335x-control.c b/drivers/usb/musb/phy-am335x-control.c
index 313c67ef7ec2..44111411ddef 100644
--- a/drivers/usb/musb/phy-am335x-control.c
+++ b/drivers/usb/musb/phy-am335x-control.c
@@ -134,9 +134,9 @@ static int am335x_control_usb_probe(struct device *dev)
const struct phy_control *phy_ctrl;
int ret;
- ret = dev_get_drvdata(dev, (const void **)&phy_ctrl);
- if (ret)
- return ret;
+ phy_ctrl = device_get_match_data(dev);
+ if (!phy_ctrl)
+ return -ENODEV;
ctrl_usb = xzalloc(sizeof(*ctrl_usb));
diff --git a/drivers/video/atmel_lcdfb_core.c b/drivers/video/atmel_lcdfb_core.c
index f2d7387b10d6..02fa753c298f 100644
--- a/drivers/video/atmel_lcdfb_core.c
+++ b/drivers/video/atmel_lcdfb_core.c
@@ -317,12 +317,12 @@ static int lcdfb_of_init(struct device *dev, struct atmel_lcdfb_info *sinfo)
struct fb_info *info = &sinfo->info;
struct display_timings *modes;
struct device_node *display;
- struct atmel_lcdfb_config *config;
+ const struct atmel_lcdfb_config *config;
int ret;
/* Driver data - optional */
- ret = dev_get_drvdata(dev, (const void **)&config);
- if (!ret) {
+ config = device_get_match_data(dev);
+ if (config) {
sinfo->have_hozval = config->have_hozval;
sinfo->have_intensity_bit = config->have_intensity_bit;
sinfo->have_alt_pixclock = config->have_alt_pixclock;
diff --git a/drivers/video/imx-ipu-v3/dw_hdmi-imx.c b/drivers/video/imx-ipu-v3/dw_hdmi-imx.c
index b2a32c406cd2..bce802bf43df 100644
--- a/drivers/video/imx-ipu-v3/dw_hdmi-imx.c
+++ b/drivers/video/imx-ipu-v3/dw_hdmi-imx.c
@@ -179,18 +179,18 @@ MODULE_DEVICE_TABLE(of, dw_hdmi_imx_dt_ids);
static int dw_hdmi_imx_probe(struct device *dev)
{
+ const struct dw_hdmi_plat_data *_plat_data;
struct dw_hdmi_plat_data *plat_data;
struct device_node *np = dev->of_node;
struct imx_hdmi *hdmi;
- int ret;
hdmi = xzalloc(sizeof(*hdmi));
- ret = dev_get_drvdata(dev, (const void **)&plat_data);
- if (ret)
- return ret;
+ _plat_data = device_get_match_data(dev);
+ if (!_plat_data)
+ return -ENODEV;
- plat_data = xmemdup(plat_data, sizeof(*plat_data));
+ plat_data = xmemdup(_plat_data, sizeof(*_plat_data));
plat_data->phy_data = hdmi;
plat_data->priv_data = hdmi;
@@ -204,9 +204,9 @@ static int dw_hdmi_imx_probe(struct device *dev)
hdmi->hdmi = dw_hdmi_bind(dev, plat_data);
if (IS_ERR(hdmi->hdmi))
- ret = PTR_ERR(hdmi->hdmi);
+ return PTR_ERR(hdmi->hdmi);
- return ret;
+ return 0;
}
struct driver dw_hdmi_imx_platform_driver = {
diff --git a/drivers/video/imx-ipu-v3/imx-ldb.c b/drivers/video/imx-ipu-v3/imx-ldb.c
index ae7d3548267a..54a5899ebb2c 100644
--- a/drivers/video/imx-ipu-v3/imx-ldb.c
+++ b/drivers/video/imx-ipu-v3/imx-ldb.c
@@ -312,9 +312,9 @@ static int imx_ldb_probe(struct device *dev)
int mapping;
const struct imx_ldb_data *devtype;
- ret = dev_get_drvdata(dev, (const void **)&devtype);
- if (ret)
- return ret;
+ devtype = device_get_match_data(dev);
+ if (!devtype)
+ return -ENODEV;
imx_ldb = xzalloc(sizeof(*imx_ldb));
imx_ldb->base = devtype->base;
diff --git a/drivers/video/imx-ipu-v3/ipu-common.c b/drivers/video/imx-ipu-v3/ipu-common.c
index f1613de42470..e5e4b48e61b0 100644
--- a/drivers/video/imx-ipu-v3/ipu-common.c
+++ b/drivers/video/imx-ipu-v3/ipu-common.c
@@ -749,9 +749,9 @@ static int ipu_probe(struct device *dev)
int i, ret;
const struct ipu_devtype *devtype;
- ret = dev_get_drvdata(dev, (const void **)&devtype);
- if (ret)
- return ret;
+ devtype = device_get_match_data(dev);
+ if (!devtype)
+ return -ENODEV;
iores = dev_request_mem_resource(dev, 0);
if (IS_ERR(iores))
diff --git a/drivers/watchdog/f71808e_wdt.c b/drivers/watchdog/f71808e_wdt.c
index 5bee06636644..7f594c8f74e9 100644
--- a/drivers/watchdog/f71808e_wdt.c
+++ b/drivers/watchdog/f71808e_wdt.c
@@ -380,13 +380,12 @@ static int f71808e_probe(struct device *dev)
{
struct f71808e_wdt *wd;
struct resource *res;
- int ret;
wd = xzalloc(sizeof(*wd));
- ret = dev_get_drvdata(dev, (const void **)&wd->variant);
- if (ret)
- return ret;
+ wd->variant = device_get_match_data(dev);
+ if (!wd->variant)
+ return -ENODEV;
res = dev_get_resource(dev->parent, IORESOURCE_IO, 0);
if (IS_ERR(res))
diff --git a/drivers/watchdog/imxulp-wdt.c b/drivers/watchdog/imxulp-wdt.c
index 5571c32ef44f..26b45d2b6c4d 100644
--- a/drivers/watchdog/imxulp-wdt.c
+++ b/drivers/watchdog/imxulp-wdt.c
@@ -107,12 +107,12 @@ static int imxulp_wd_probe(struct device *dev)
{
struct imxulp_wd *imxwd;
struct resource *iores;
- struct imxulp_socdata *socdata;
+ const struct imxulp_socdata *socdata;
int ret;
- ret = dev_get_drvdata(dev, (const void **)&socdata);
- if (ret)
- return ret;
+ socdata = device_get_match_data(dev);
+ if (!socdata)
+ return -ENODEV;
imxwd = xzalloc(sizeof(*imxwd));
iores = dev_request_mem_resource(dev, 0);
diff --git a/drivers/watchdog/imxwd.c b/drivers/watchdog/imxwd.c
index 35c688fc2701..e74638f9419c 100644
--- a/drivers/watchdog/imxwd.c
+++ b/drivers/watchdog/imxwd.c
@@ -234,12 +234,12 @@ static int imx_wd_probe(struct device *dev)
struct resource *iores;
struct imx_wd *priv;
struct clk *clk;
- void *ops;
+ const struct imx_wd_ops *ops;
int ret;
- ret = dev_get_drvdata(dev, (const void **)&ops);
- if (ret)
- return ret;
+ ops = device_get_match_data(dev);
+ if (!ops)
+ return -ENODEV;
priv = xzalloc(sizeof(struct imx_wd));
iores = dev_request_mem_resource(dev, 0);
diff --git a/drivers/watchdog/stm32_iwdg.c b/drivers/watchdog/stm32_iwdg.c
index c47a8cac15ec..b8b4fd07fb82 100644
--- a/drivers/watchdog/stm32_iwdg.c
+++ b/drivers/watchdog/stm32_iwdg.c
@@ -132,7 +132,7 @@ MODULE_DEVICE_TABLE(of, stm32_iwdg_of_match);
static int stm32_iwdg_probe(struct device *dev)
{
- struct stm32_iwdg_data *data;
+ const struct stm32_iwdg_data *data;
struct stm32_iwdg *wd;
struct resource *res;
struct watchdog *wdd;
@@ -141,8 +141,8 @@ static int stm32_iwdg_probe(struct device *dev)
wd = xzalloc(sizeof(*wd));
- ret = dev_get_drvdata(dev, (const void **)&data);
- if (ret)
+ data = device_get_match_data(dev);
+ if (!data)
return -ENODEV;
res = dev_request_mem_resource(dev, 0);
--
2.39.5
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/8] ARM: i.MX: esdctl: replace dev_get_drvdata with device_get_match_data
2025-05-06 6:34 [PATCH 1/8] treewide: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
@ 2025-05-06 6:34 ` Ahmad Fatoum
2025-05-06 6:34 ` [PATCH 3/8] driver: switch dev_get_drvdata to Linux semantics Ahmad Fatoum
` (6 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2025-05-06 6:34 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
In preparation for aligning dev_get_drvdata with Linux, use
device_get_match_data instead. To not cast const-ness away, make all the
match data related types const.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/mach-imx/esdctl.c | 65 +++++++++++++++++++-------------------
1 file changed, 32 insertions(+), 33 deletions(-)
diff --git a/arch/arm/mach-imx/esdctl.c b/arch/arm/mach-imx/esdctl.c
index 701ca0ac1f37..4b67b52ca45e 100644
--- a/arch/arm/mach-imx/esdctl.c
+++ b/arch/arm/mach-imx/esdctl.c
@@ -35,7 +35,7 @@
struct imx_esdctl_data {
unsigned long base0;
unsigned long base1;
- int (*add_mem)(void *esdctlbase, struct imx_esdctl_data *);
+ int (*add_mem)(void *esdctlbase, const struct imx_esdctl_data *);
};
static int imx_esdctl_disabled;
@@ -229,19 +229,19 @@ static inline void imx_esdctl_v2_disable_default(void __iomem *esdctlbase)
}
}
-static int imx_esdctl_v1_add_mem(void *esdctlbase, struct imx_esdctl_data *data)
+static int imx_esdctl_v1_add_mem(void *esdctlbase, const struct imx_esdctl_data *data)
{
return add_mem(data->base0, imx_v1_sdram_size(esdctlbase, 0),
data->base1, imx_v1_sdram_size(esdctlbase, 1));
}
-static int imx_esdctl_v2_add_mem(void *esdctlbase, struct imx_esdctl_data *data)
+static int imx_esdctl_v2_add_mem(void *esdctlbase, const struct imx_esdctl_data *data)
{
return add_mem(data->base0, imx_v2_sdram_size(esdctlbase, 0),
data->base1, imx_v2_sdram_size(esdctlbase, 1));
}
-static int imx_esdctl_v2_bug_add_mem(void *esdctlbase, struct imx_esdctl_data *data)
+static int imx_esdctl_v2_bug_add_mem(void *esdctlbase, const struct imx_esdctl_data *data)
{
imx_esdctl_v2_disable_default(esdctlbase);
@@ -249,13 +249,13 @@ static int imx_esdctl_v2_bug_add_mem(void *esdctlbase, struct imx_esdctl_data *d
data->base1, imx_v2_sdram_size(esdctlbase, 1));
}
-static int imx_esdctl_v3_add_mem(void *esdctlbase, struct imx_esdctl_data *data)
+static int imx_esdctl_v3_add_mem(void *esdctlbase, const struct imx_esdctl_data *data)
{
return add_mem(data->base0, imx_v3_sdram_size(esdctlbase, 0),
data->base1, imx_v3_sdram_size(esdctlbase, 1));
}
-static int imx_esdctl_v4_add_mem(void *esdctlbase, struct imx_esdctl_data *data)
+static int imx_esdctl_v4_add_mem(void *esdctlbase, const struct imx_esdctl_data *data)
{
return add_mem(data->base0, imx_v4_sdram_size(esdctlbase, 0),
data->base1, imx_v4_sdram_size(esdctlbase, 1));
@@ -286,7 +286,7 @@ static inline resource_size_t imx6_mmdc_sdram_size(void __iomem *mmdcbase)
return size;
}
-static int imx6_mmdc_add_mem(void *mmdcbase, struct imx_esdctl_data *data)
+static int imx6_mmdc_add_mem(void *mmdcbase, const struct imx_esdctl_data *data)
{
return arm_add_mem_device("ram0", data->base0,
imx6_mmdc_sdram_size(mmdcbase));
@@ -308,7 +308,7 @@ static inline resource_size_t vf610_ddrmc_sdram_size(void __iomem *ddrmc)
return memory_sdram_size(cols, rows, banks, width);
}
-static int vf610_ddrmc_add_mem(void *mmdcbase, struct imx_esdctl_data *data)
+static int vf610_ddrmc_add_mem(void *mmdcbase, const struct imx_esdctl_data *data)
{
return arm_add_mem_device("ram0", data->base0,
vf610_ddrmc_sdram_size(mmdcbase));
@@ -513,7 +513,7 @@ static resource_size_t imx8m_ddrc_sdram_size(void __iomem *ddrc, unsigned buswid
reduced_adress_space, mstr);
}
-static int _imx8m_ddrc_add_mem(void *mmdcbase, struct imx_esdctl_data *data,
+static int _imx8m_ddrc_add_mem(void *mmdcbase, const struct imx_esdctl_data *data,
unsigned int buswidth)
{
resource_size_t size = imx8m_ddrc_sdram_size(mmdcbase, buswidth);
@@ -548,12 +548,12 @@ static int _imx8m_ddrc_add_mem(void *mmdcbase, struct imx_esdctl_data *data,
return ret;
}
-static int imx8m_ddrc_add_mem(void *mmdcbase, struct imx_esdctl_data *data)
+static int imx8m_ddrc_add_mem(void *mmdcbase, const struct imx_esdctl_data *data)
{
return _imx8m_ddrc_add_mem(mmdcbase, data, 32);
}
-static int imx8mn_ddrc_add_mem(void *mmdcbase, struct imx_esdctl_data *data)
+static int imx8mn_ddrc_add_mem(void *mmdcbase, const struct imx_esdctl_data *data)
{
return _imx8m_ddrc_add_mem(mmdcbase, data, 16);
}
@@ -592,7 +592,7 @@ resource_size_t imx9_ddrc_sdram_size(void)
return mem;
}
-static int imx9_ddrc_add_mem(void *mmdcbase, struct imx_esdctl_data *data)
+static int imx9_ddrc_add_mem(void *mmdcbase, const struct imx_esdctl_data *data)
{
return arm_add_mem_device("ram0", data->base0, imx9_ddrc_sdram_size());
}
@@ -637,7 +637,7 @@ static resource_size_t imx7d_ddrc_sdram_size(void __iomem *ddrc)
reduced_adress_space, mstr);
}
-static int imx7d_ddrc_add_mem(void *mmdcbase, struct imx_esdctl_data *data)
+static int imx7d_ddrc_add_mem(void *mmdcbase, const struct imx_esdctl_data *data)
{
return arm_add_mem_device("ram0", data->base0,
imx7d_ddrc_sdram_size(mmdcbase));
@@ -646,13 +646,12 @@ static int imx7d_ddrc_add_mem(void *mmdcbase, struct imx_esdctl_data *data)
static int imx_esdctl_probe(struct device *dev)
{
struct resource *iores;
- struct imx_esdctl_data *data;
- int ret;
+ const struct imx_esdctl_data *data;
void *base;
- ret = dev_get_drvdata(dev, (const void **)&data);
- if (ret)
- return ret;
+ data = device_get_match_data(dev);
+ if (!data)
+ return -ENODEV;
iores = dev_request_mem_resource(dev, 0);
if (IS_ERR(iores))
@@ -665,84 +664,84 @@ static int imx_esdctl_probe(struct device *dev)
return data->add_mem(base, data);
}
-static __maybe_unused struct imx_esdctl_data imx1_data = {
+static __maybe_unused const struct imx_esdctl_data imx1_data = {
.base0 = MX1_CSD0_BASE_ADDR,
.base1 = MX1_CSD1_BASE_ADDR,
.add_mem = imx_esdctl_v1_add_mem,
};
-static __maybe_unused struct imx_esdctl_data imx25_data = {
+static __maybe_unused const struct imx_esdctl_data imx25_data = {
.base0 = MX25_CSD0_BASE_ADDR,
.base1 = MX25_CSD1_BASE_ADDR,
.add_mem = imx_esdctl_v2_add_mem,
};
-static __maybe_unused struct imx_esdctl_data imx27_data = {
+static __maybe_unused const struct imx_esdctl_data imx27_data = {
.base0 = MX27_CSD0_BASE_ADDR,
.base1 = MX27_CSD1_BASE_ADDR,
.add_mem = imx_esdctl_v2_bug_add_mem,
};
-static __maybe_unused struct imx_esdctl_data imx31_data = {
+static __maybe_unused const struct imx_esdctl_data imx31_data = {
.base0 = MX31_CSD0_BASE_ADDR,
.base1 = MX31_CSD1_BASE_ADDR,
.add_mem = imx_esdctl_v2_bug_add_mem,
};
-static __maybe_unused struct imx_esdctl_data imx35_data = {
+static __maybe_unused const struct imx_esdctl_data imx35_data = {
.base0 = MX35_CSD0_BASE_ADDR,
.base1 = MX35_CSD1_BASE_ADDR,
.add_mem = imx_esdctl_v2_bug_add_mem,
};
-static __maybe_unused struct imx_esdctl_data imx51_data = {
+static __maybe_unused const struct imx_esdctl_data imx51_data = {
.base0 = MX51_CSD0_BASE_ADDR,
.base1 = MX51_CSD1_BASE_ADDR,
.add_mem = imx_esdctl_v3_add_mem,
};
-static __maybe_unused struct imx_esdctl_data imx53_data = {
+static __maybe_unused const struct imx_esdctl_data imx53_data = {
.base0 = MX53_CSD0_BASE_ADDR,
.base1 = MX53_CSD1_BASE_ADDR,
.add_mem = imx_esdctl_v4_add_mem,
};
-static __maybe_unused struct imx_esdctl_data imx6q_data = {
+static __maybe_unused const struct imx_esdctl_data imx6q_data = {
.base0 = MX6_MMDC_PORT01_BASE_ADDR,
.add_mem = imx6_mmdc_add_mem,
};
-static __maybe_unused struct imx_esdctl_data imx6sx_data = {
+static __maybe_unused const struct imx_esdctl_data imx6sx_data = {
.base0 = MX6_MMDC_PORT0_BASE_ADDR,
.add_mem = imx6_mmdc_add_mem,
};
-static __maybe_unused struct imx_esdctl_data imx6ul_data = {
+static __maybe_unused const struct imx_esdctl_data imx6ul_data = {
.base0 = MX6_MMDC_PORT0_BASE_ADDR,
.add_mem = imx6_mmdc_add_mem,
};
-static __maybe_unused struct imx_esdctl_data vf610_data = {
+static __maybe_unused const struct imx_esdctl_data vf610_data = {
.base0 = VF610_RAM_BASE_ADDR,
.add_mem = vf610_ddrmc_add_mem,
};
-static __maybe_unused struct imx_esdctl_data imx8m_data = {
+static __maybe_unused const struct imx_esdctl_data imx8m_data = {
.base0 = MX8M_DDR_CSD1_BASE_ADDR,
.add_mem = imx8m_ddrc_add_mem,
};
-static __maybe_unused struct imx_esdctl_data imx8mn_data = {
+static __maybe_unused const struct imx_esdctl_data imx8mn_data = {
.base0 = MX8M_DDR_CSD1_BASE_ADDR,
.add_mem = imx8mn_ddrc_add_mem,
};
-static __maybe_unused struct imx_esdctl_data imx9_data = {
+static __maybe_unused const struct imx_esdctl_data imx9_data = {
.base0 = MX9_DDR_CSD1_BASE_ADDR,
.add_mem = imx9_ddrc_add_mem,
};
-static __maybe_unused struct imx_esdctl_data imx7d_data = {
+static __maybe_unused const struct imx_esdctl_data imx7d_data = {
.base0 = MX7_DDR_BASE_ADDR,
.add_mem = imx7d_ddrc_add_mem,
};
--
2.39.5
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/8] driver: switch dev_get_drvdata to Linux semantics
2025-05-06 6:34 [PATCH 1/8] treewide: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
2025-05-06 6:34 ` [PATCH 2/8] ARM: i.MX: esdctl: " Ahmad Fatoum
@ 2025-05-06 6:34 ` Ahmad Fatoum
2025-05-06 6:34 ` [PATCH 4/8] gpio: gpio-mxs: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
` (5 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2025-05-06 6:34 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Now that no users of dev_get_drvdata remain, replace it with the Linux
version. Any out-of-tree users must be changed to use
device_get_match_data instead. The new dev_get_drvdata is the equivalent
of what was so far written as dev->priv.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/base/driver.c | 15 ---------------
include/device.h | 5 ++++-
include/driver.h | 12 ------------
include/linux/device.h | 32 ++++++++++++++++++++++++++++++++
4 files changed, 36 insertions(+), 28 deletions(-)
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 85cec7efab46..2160d2fd060b 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -709,21 +709,6 @@ static void devices_shutdown(void)
}
devshutdown_exitcall(devices_shutdown);
-int dev_get_drvdata(struct device *dev, const void **data)
-{
- if (dev->of_id_entry) {
- *data = dev->of_id_entry->data;
- return 0;
- }
-
- if (dev->id_entry) {
- *data = (const void **)dev->id_entry->driver_data;
- return 0;
- }
-
- return -ENODEV;
-}
-
const void *device_get_match_data(struct device *dev)
{
if (dev->of_id_entry)
diff --git a/include/device.h b/include/device.h
index 8841197a0a56..bc3a348e2e15 100644
--- a/include/device.h
+++ b/include/device.h
@@ -54,7 +54,10 @@ struct device {
/*! Devices of a particular class normaly need to store more
* information than struct device holds.
*/
- void *priv;
+ union {
+ void *priv;
+ void *driver_data;
+ };
void *type_data; /*! In case this device is a specific device, this pointer
* points to the type specific device, i.e. eth_device
*/
diff --git a/include/driver.h b/include/driver.h
index d73c33a42a81..b63dce84c80e 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -666,18 +666,6 @@ int cdevfs_del_partition(struct cdev *cdev);
#define DRV_OF_COMPAT(compat) of_match_ptr(compat)
-/**
- * dev_get_drvdata - get driver match data associated with device
- * @dev: device instance
- * @data: pointer to void *, where match data is stored
- *
- * Returns 0 on success and error code otherwise.
- *
- * DEPRECATED: use device_get_match_data instead, which avoids
- * common pitfalls due to explicit pointer casts
- */
-int dev_get_drvdata(struct device *dev, const void **data);
-
/**
* device_get_match_data - get driver match data associated with device
* @dev: device instance
diff --git a/include/linux/device.h b/include/linux/device.h
index 661d8b24730e..d4098b85239f 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -73,4 +73,36 @@ static inline int bus_for_each_dev(const struct bus_type *bus, struct device *st
return 0;
}
+
+/**
+ * dev_set_drvdata - set driver private data for device
+ * @dev: device instance
+ * @data: driver-specific data
+ *
+ * Returns private driver data or NULL if none was set.
+ *
+ * NOTE: This does _not_ return the match data associated with
+ * the match. For that use device_get_match_data instead.
+ */
+static inline void dev_set_drvdata(struct device *dev, void *data)
+{
+ dev->driver_data = data;
+}
+
+/**
+ * dev_get_drvdata - get driver match data associated for device
+ * @dev: device instance
+ * @data: driver-specific data
+ *
+ * Set some driver and device specific data for later retrieval
+ * by dev_get_drvdata.
+ *
+ * NOTE: This does _not_ return the match data associated with
+ * the match. For that use device_get_match_data instead.
+ */
+static inline void *dev_get_drvdata(const struct device *dev)
+{
+ return dev->driver_data;
+}
+
#endif
--
2.39.5
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 4/8] gpio: gpio-mxs: replace dev_get_drvdata with device_get_match_data
2025-05-06 6:34 [PATCH 1/8] treewide: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
2025-05-06 6:34 ` [PATCH 2/8] ARM: i.MX: esdctl: " Ahmad Fatoum
2025-05-06 6:34 ` [PATCH 3/8] driver: switch dev_get_drvdata to Linux semantics Ahmad Fatoum
@ 2025-05-06 6:34 ` Ahmad Fatoum
2025-05-06 7:42 ` Sascha Hauer
2025-05-06 6:34 ` [PATCH 5/8] mci: am654-sdhci: fix error code printed in error messages Ahmad Fatoum
` (4 subsequent siblings)
7 siblings, 1 reply; 10+ messages in thread
From: Ahmad Fatoum @ 2025-05-06 6:34 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
In preparation for aligning dev_get_drvdata with Linux, use
device_get_match_data instead.
While at it, we drop the unneeded struct mxs_gpio_chip::regs member to
not have to worry about const safety.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/gpio/gpio-mxs.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c
index 770acb61c858..df698eb19167 100644
--- a/drivers/gpio/gpio-mxs.c
+++ b/drivers/gpio/gpio-mxs.c
@@ -19,7 +19,6 @@ struct mxs_gpio_chip {
void __iomem *doe;
void __iomem *dout;
struct gpio_chip chip;
- struct mxs_gpio_regs *regs;
};
struct mxs_gpio_regs {
@@ -101,12 +100,12 @@ static struct gpio_ops mxs_gpio_ops = {
static int mxs_gpio_probe(struct device *dev)
{
struct mxs_gpio_chip *mxsgpio;
- struct mxs_gpio_regs *regs;
- int ret, id;
+ const struct mxs_gpio_regs *regs;
+ int id;
- ret = dev_get_drvdata(dev, (const void **)®s);
- if (ret)
- return ret;
+ regs = device_get_match_data(dev);
+ if (!regs)
+ return -ENODEV;
mxsgpio = xzalloc(sizeof(*mxsgpio));
mxsgpio->chip.ops = &mxs_gpio_ops;
@@ -131,7 +130,6 @@ static int mxs_gpio_probe(struct device *dev)
mxsgpio->chip.ngpio = 32;
mxsgpio->chip.dev = dev;
- mxsgpio->regs = regs;
gpiochip_add(&mxsgpio->chip);
dev_dbg(dev, "probed gpiochip%d with base %d\n", dev->id, mxsgpio->chip.base);
--
2.39.5
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 5/8] mci: am654-sdhci: fix error code printed in error messages
2025-05-06 6:34 [PATCH 1/8] treewide: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
` (2 preceding siblings ...)
2025-05-06 6:34 ` [PATCH 4/8] gpio: gpio-mxs: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
@ 2025-05-06 6:34 ` Ahmad Fatoum
2025-05-06 6:34 ` [PATCH 6/8] pinctrl: at91: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
` (3 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2025-05-06 6:34 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The error code returned on clock failures is a stale value of ret, which
is likely to be zero.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/mci/am654-sdhci.c | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
diff --git a/drivers/mci/am654-sdhci.c b/drivers/mci/am654-sdhci.c
index b4735952515f..3e637c56850f 100644
--- a/drivers/mci/am654-sdhci.c
+++ b/drivers/mci/am654-sdhci.c
@@ -575,21 +575,13 @@ static int am654_sdhci_probe(struct device *dev)
return PTR_ERR(plat->base);
}
- plat->clk = clk_get(dev, "clk_xin");
- if (IS_ERR(plat->clk)) {
- dev_err(dev, "failed to get clock\n");
- return ret;
- }
+ plat->clk = clk_get_enabled(dev, "clk_xin");
+ if (IS_ERR(plat->clk))
+ return dev_errp_probe(dev, plat->clk, "failed to get clock\n");
- clk_enable(plat->clk);
-
- plat->clk_ahb = clk_get(dev, "clk_ahb");
- if (IS_ERR(plat->clk_ahb)) {
- dev_err(dev, "failed to get ahb clock\n");
- return ret;
- }
-
- clk_enable(plat->clk_ahb);
+ plat->clk_ahb = clk_get_enabled(dev, "clk_ahb");
+ if (IS_ERR(plat->clk_ahb))
+ return dev_errp_probe(dev, plat->clk, "failed to get ahb clock\n");
mci = &plat->mci;
mci->f_max = clk_get_rate(plat->clk);
--
2.39.5
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 6/8] pinctrl: at91: replace dev_get_drvdata with device_get_match_data
2025-05-06 6:34 [PATCH 1/8] treewide: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
` (3 preceding siblings ...)
2025-05-06 6:34 ` [PATCH 5/8] mci: am654-sdhci: fix error code printed in error messages Ahmad Fatoum
@ 2025-05-06 6:34 ` Ahmad Fatoum
2025-05-06 6:34 ` [PATCH 7/8] drivers: maintain const when converting from struct driver Ahmad Fatoum
` (2 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2025-05-06 6:34 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
dev_get_drvdata() and device_get_match_data() can already deal with both
OF and non-OF match data, so at91_pinctrl_get_driver_data only adds some
unneeded complexity. Remove it and while at it switch to the less
error-prone device_get_match_data.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/pinctrl/pinctrl-at91.c | 27 +++------------------------
1 file changed, 3 insertions(+), 24 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c
index 25b4d084ed6d..eb0ce648095d 100644
--- a/drivers/pinctrl/pinctrl-at91.c
+++ b/drivers/pinctrl/pinctrl-at91.c
@@ -26,13 +26,13 @@
struct at91_pinctrl {
struct pinctrl_device pctl;
- struct at91_pinctrl_mux_ops *ops;
+ const struct at91_pinctrl_mux_ops *ops;
};
struct at91_gpio_chip {
struct gpio_chip chip;
void __iomem *regbase; /* PIO bank virtual address */
- struct at91_pinctrl_mux_ops *ops; /* ops */
+ const struct at91_pinctrl_mux_ops *ops; /* ops */
};
#define MAX_GPIO_BANKS 5
@@ -384,27 +384,6 @@ static struct of_device_id at91_pinctrl_dt_ids[] = {
};
MODULE_DEVICE_TABLE(of, at91_pinctrl_dt_ids);
-static struct at91_pinctrl_mux_ops *at91_pinctrl_get_driver_data(struct device *dev)
-{
- struct at91_pinctrl_mux_ops *ops_data = NULL;
- int rc;
-
- if (dev->of_node) {
- const struct of_device_id *match;
- match = of_match_node(at91_pinctrl_dt_ids, dev->of_node);
- if (!match)
- ops_data = NULL;
- else
- ops_data = (struct at91_pinctrl_mux_ops *)match->data;
- } else {
- rc = dev_get_drvdata(dev, (const void **)&ops_data);
- if (rc)
- ops_data = NULL;
- }
-
- return ops_data;
-}
-
static int at91_pinctrl_set_conf(struct at91_pinctrl *info, unsigned int pin_num, unsigned int mux, unsigned int conf)
{
unsigned int mask;
@@ -492,7 +471,7 @@ static int at91_pinctrl_probe(struct device *dev)
info = xzalloc(sizeof(struct at91_pinctrl));
- info->ops = at91_pinctrl_get_driver_data(dev);
+ info->ops = device_get_match_data(dev);
if (!info->ops) {
dev_err(dev, "failed to retrieve driver data\n");
return -ENODEV;
--
2.39.5
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 7/8] drivers: maintain const when converting from struct driver
2025-05-06 6:34 [PATCH 1/8] treewide: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
` (4 preceding siblings ...)
2025-05-06 6:34 ` [PATCH 6/8] pinctrl: at91: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
@ 2025-05-06 6:34 ` Ahmad Fatoum
2025-05-06 6:34 ` [PATCH 8/8] driver: base: invert driver match callback for Linux compatibility Ahmad Fatoum
2025-05-06 7:41 ` [PATCH 1/8] treewide: replace dev_get_drvdata with device_get_match_data Sascha Hauer
7 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2025-05-06 6:34 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
In preparation for making the struct driver parameter to the match
callbacks const, introduce container_of_const and make use of it instead
of normal container in upcasting macros.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/acpi.h | 5 +----
include/efi/efi-device.h | 5 +----
include/linux/container_of.h | 14 ++++++++++++++
include/linux/virtio.h | 10 ++--------
4 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/include/acpi.h b/include/acpi.h
index fc0da30610a6..fa94d972e3fe 100644
--- a/include/acpi.h
+++ b/include/acpi.h
@@ -125,10 +125,7 @@ struct acpi_driver {
extern struct bus_type acpi_bus;
-static inline struct acpi_driver *to_acpi_driver(struct driver *drv)
-{
- return container_of(drv, struct acpi_driver, driver);
-}
+#define to_acpi_driver(drv) container_of_const((drv), struct acpi_driver, driver)
#define device_acpi_driver(drv) \
register_efi_driver_macro(device, acpi, drv)
diff --git a/include/efi/efi-device.h b/include/efi/efi-device.h
index 5d2110356fd4..a8fc99a0e12b 100644
--- a/include/efi/efi-device.h
+++ b/include/efi/efi-device.h
@@ -33,10 +33,7 @@ static inline struct efi_device *to_efi_device(struct device *dev)
return container_of(dev, struct efi_device, dev);
}
-static inline struct efi_driver *to_efi_driver(struct driver *drv)
-{
- return container_of(drv, struct efi_driver, driver);
-}
+#define to_efi_driver(drv) container_of_const((drv), struct efi_driver, driver)
static inline int efi_driver_register(struct efi_driver *efidrv)
{
diff --git a/include/linux/container_of.h b/include/linux/container_of.h
index 2f4944b791b8..8669ef0154d9 100644
--- a/include/linux/container_of.h
+++ b/include/linux/container_of.h
@@ -21,6 +21,20 @@
"pointer type mismatch in container_of()"); \
((type *)(__mptr - offsetof(type, member))); })
+
+/**
+ * container_of_const - cast a member of a structure out to the containing
+ * structure and preserve the const-ness of the pointer
+ * @ptr: the pointer to the member
+ * @type: the type of the container struct this is embedded in.
+ * @member: the name of the member within the struct.
+ */
+#define container_of_const(ptr, type, member) \
+ _Generic(ptr, \
+ const typeof(*(ptr)) *: ((const type *)container_of(ptr, type, member)),\
+ default: ((type *)container_of(ptr, type, member)) \
+ )
+
/**
* container_of_safe - cast a member of a structure out to the containing structure
* @ptr: the pointer to the member.
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index 3d4c88336055..eb4293003294 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -43,10 +43,7 @@ struct virtio_device {
u32 status_param;
};
-static inline struct virtio_device *dev_to_virtio(struct device *_dev)
-{
- return container_of(_dev, struct virtio_device, dev);
-}
+#define dev_to_virtio(_dev) container_of_const(_dev, struct virtio_device, dev)
void virtio_add_status(struct virtio_device *dev, unsigned int status);
int register_virtio_device(struct virtio_device *dev);
@@ -96,10 +93,7 @@ struct virtio_driver {
void (*config_changed)(struct virtio_device *dev);
};
-static inline struct virtio_driver *drv_to_virtio(struct driver *drv)
-{
- return container_of(drv, struct virtio_driver, driver);
-}
+#define drv_to_virtio(__drv) container_of_const(__drv, struct virtio_driver, driver)
int virtio_driver_register(struct virtio_driver *drv);
--
2.39.5
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 8/8] driver: base: invert driver match callback for Linux compatibility
2025-05-06 6:34 [PATCH 1/8] treewide: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
` (5 preceding siblings ...)
2025-05-06 6:34 ` [PATCH 7/8] drivers: maintain const when converting from struct driver Ahmad Fatoum
@ 2025-05-06 6:34 ` Ahmad Fatoum
2025-05-06 7:41 ` [PATCH 1/8] treewide: replace dev_get_drvdata with device_get_match_data Sascha Hauer
7 siblings, 0 replies; 10+ messages in thread
From: Ahmad Fatoum @ 2025-05-06 6:34 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Both Linux and barebox have a struct bus_type::match callback that
checks whether a driver matches a device.
In Linux, a match is indicated by a non-zero return code, but in barebox
zero is used for that purpose.
To avoid this annoying pitfall, let's switch over barebox to the Linux
scheme. While at it, we also adapt the prototype to make the driver
const as is the case with Linux. This gives us some extra certainty that
all bus types have indeed been adapted.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/amba/bus.c | 7 +++----
drivers/base/bus.c | 20 ++++++++++----------
drivers/base/driver.c | 2 +-
drivers/bus/acpi.c | 6 +++---
drivers/efi/efi-device.c | 8 ++++----
drivers/firmware/arm_scmi/bus.c | 10 +++++-----
drivers/net/phy/mdio_bus.c | 10 +++++-----
drivers/of/base.c | 6 +++---
drivers/pci/bus.c | 8 ++++----
drivers/tee/tee_core.c | 6 +++---
drivers/usb/core/usb.c | 8 ++++----
drivers/usb/gadget/udc/core.c | 10 +++++-----
drivers/virtio/virtio.c | 8 ++++----
drivers/w1/w1.c | 8 ++++----
fs/fs.c | 4 ++--
include/driver.h | 12 +++++++++---
include/of.h | 2 +-
17 files changed, 70 insertions(+), 65 deletions(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 5ed8336e6124..8d6525cca967 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -29,13 +29,12 @@ amba_lookup(const struct amba_id *table, struct amba_device *dev)
return ret ? table : NULL;
}
-static int amba_match(struct device *dev, struct driver *drv)
+static int amba_match(struct device *dev, const struct driver *drv)
{
struct amba_device *pcdev = to_amba_device(dev);
+ const struct amba_driver *pcdrv = to_amba_driver(drv);
- struct amba_driver *pcdrv = to_amba_driver(drv);
-
- return amba_lookup(pcdrv->id_table, pcdev) == NULL;
+ return amba_lookup(pcdrv->id_table, pcdev) != NULL;
}
static int amba_get_enable_pclk(struct amba_device *pcdev)
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index a5c9c930da83..58fcd2e032da 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -47,7 +47,7 @@ int bus_register(struct bus_type *bus)
return 0;
}
-int device_match(struct device *dev, struct driver *drv)
+int device_match(struct device *dev, const struct driver *drv)
{
if (IS_ENABLED(CONFIG_OFDEVICE) && dev->of_node &&
drv->of_compatible)
@@ -59,29 +59,29 @@ int device_match(struct device *dev, struct driver *drv)
while (id->name) {
if (!strcmp(id->name, dev->name)) {
dev->id_entry = id;
- return 0;
+ return true;
}
id++;
}
} else if (!strcmp(dev->name, drv->name)) {
- return 0;
+ return true;
}
- return -1;
+ return false;
}
-int device_match_of_modalias(struct device *dev, struct driver *drv)
+int device_match_of_modalias(struct device *dev, const struct driver *drv)
{
const struct platform_device_id *id = drv->id_table;
const char *of_modalias = NULL, *p;
const struct property *prop;
const char *compat;
- if (!device_match(dev, drv))
- return 0;
+ if (device_match(dev, drv))
+ return true;
if (!id || !IS_ENABLED(CONFIG_OFDEVICE) || !dev->of_node)
- return -1;
+ return false;
of_property_for_each_string(dev->of_node, "compatible", prop, compat) {
p = strchr(compat, ',');
@@ -90,10 +90,10 @@ int device_match_of_modalias(struct device *dev, struct driver *drv)
for (id = drv->id_table; id->name; id++) {
if (!strcmp(id->name, dev->name) || !strcmp(id->name, of_modalias)) {
dev->id_entry = id;
- return 0;
+ return true;
}
}
}
- return -1;
+ return false;
}
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 2160d2fd060b..2192ba9812cb 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -226,7 +226,7 @@ static int match(struct driver *drv, struct device *dev)
dev->driver = drv;
- if (dev->bus->match && dev->bus->match(dev, drv))
+ if (!driver_match_device(drv, dev))
goto err_out;
ret = device_probe(dev);
if (ret)
diff --git a/drivers/bus/acpi.c b/drivers/bus/acpi.c
index 81e37cace710..92325c16e234 100644
--- a/drivers/bus/acpi.c
+++ b/drivers/bus/acpi.c
@@ -199,12 +199,12 @@ static int acpi_register_devices(struct bus_type *bus)
return 0;
}
-static int acpi_bus_match(struct device *dev, struct driver *drv)
+static int acpi_bus_match(struct device *dev, const struct driver *drv)
{
- struct acpi_driver *acpidrv = to_acpi_driver(drv);
+ const struct acpi_driver *acpidrv = to_acpi_driver(drv);
struct acpi_sdt *sdt = acpi_get_dev_sdt(dev);
- return acpi_sigcmp(acpidrv->signature, sdt->signature);
+ return !acpi_sigcmp(acpidrv->signature, sdt->signature);
}
struct bus_type acpi_bus = {
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index a113dfb45f3b..6dfcf22d3baf 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -282,9 +282,9 @@ int efi_connect_all(void)
return 0;
}
-static int efi_bus_match(struct device *dev, struct driver *drv)
+static int efi_bus_match(struct device *dev, const struct driver *drv)
{
- struct efi_driver *efidrv = to_efi_driver(drv);
+ const struct efi_driver *efidrv = to_efi_driver(drv);
struct efi_device *efidev = to_efi_device(dev);
int i;
@@ -292,11 +292,11 @@ static int efi_bus_match(struct device *dev, struct driver *drv)
if (!efi_guidcmp(efidrv->guid, efidev->guids[i])) {
BS->handle_protocol(efidev->handle, &efidev->guids[i],
&efidev->protocol);
- return 0;
+ return true;
}
}
- return 1;
+ return false;
}
static int efi_bus_probe(struct device *dev)
diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
index 1d9a0f089b44..0d7c404ae5ed 100644
--- a/drivers/firmware/arm_scmi/bus.c
+++ b/drivers/firmware/arm_scmi/bus.c
@@ -139,7 +139,7 @@ static int scmi_protocol_device_request(const struct scmi_device_id *id_table)
}
static const struct scmi_device_id *
-scmi_dev_match_id(struct scmi_device *scmi_dev, struct scmi_driver *scmi_drv)
+scmi_dev_match_id(struct scmi_device *scmi_dev, const struct scmi_driver *scmi_drv)
{
const struct scmi_device_id *id = scmi_drv->id_table;
@@ -157,17 +157,17 @@ scmi_dev_match_id(struct scmi_device *scmi_dev, struct scmi_driver *scmi_drv)
return NULL;
}
-static int scmi_dev_match(struct device *dev, struct driver *drv)
+static int scmi_dev_match(struct device *dev, const struct driver *drv)
{
- struct scmi_driver *scmi_drv = to_scmi_driver(drv);
+ const struct scmi_driver *scmi_drv = to_scmi_driver(drv);
struct scmi_device *scmi_dev = to_scmi_dev(dev);
const struct scmi_device_id *id;
id = scmi_dev_match_id(scmi_dev, scmi_drv);
if (id)
- return 0;
+ return true;
- return -1;
+ return false;
}
static int scmi_match_by_id_table(struct device *dev, void *data)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 7974ca773899..a6671a2680ad 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -415,20 +415,20 @@ EXPORT_SYMBOL(of_mdio_find_bus);
* Description: Given a PHY device, and a PHY driver, return 0 if
* the driver supports the device. Otherwise, return 1.
*/
-static int mdio_bus_match(struct device *dev, struct driver *drv)
+static int mdio_bus_match(struct device *dev, const struct driver *drv)
{
- struct phy_device *phydev = to_phy_device(dev);
- struct phy_driver *phydrv = to_phy_driver(drv);
+ const struct phy_device *phydev = to_phy_device(dev);
+ const struct phy_driver *phydrv = to_phy_driver(drv);
if (phydrv->is_phy) {
if ((phydrv->phy_id & phydrv->phy_id_mask) ==
(phydev->phy_id & phydrv->phy_id_mask))
- return 0;
+ return true;
} else {
return device_match(dev, drv);
}
- return 1;
+ return false;
}
/**
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 8184b284099e..1439e55a0aac 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -842,17 +842,17 @@ struct device_node *of_find_matching_node_and_match(struct device_node *from,
}
EXPORT_SYMBOL(of_find_matching_node_and_match);
-int of_match(struct device *dev, struct driver *drv)
+bool of_match(struct device *dev, const struct driver *drv)
{
const struct of_device_id *id;
id = of_match_node(drv->of_compatible, dev->of_node);
if (!id)
- return 1;
+ return false;
dev->of_id_entry = id;
- return 0;
+ return true;
}
EXPORT_SYMBOL(of_match);
/**
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 37bdc9a22f43..c8f5b592428d 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -73,19 +73,19 @@ const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
}
EXPORT_SYMBOL(pci_match_id);
-static int pci_match(struct device *dev, struct driver *drv)
+static int pci_match(struct device *dev, const struct driver *drv)
{
struct pci_dev *pdev = to_pci_dev(dev);
- struct pci_driver *pdrv = to_pci_driver(drv);
+ const struct pci_driver *pdrv = to_pci_driver(drv);
const struct pci_device_id *id;
for (id = pdrv->id_table; id->vendor; id++)
if (pci_match_one_device(id, pdev)) {
pdev->id = id;
- return 0;
+ return true;
}
- return -1;
+ return false;
}
static int pci_probe(struct device *dev)
diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c
index 57a1d95d90d0..593e85313b0a 100644
--- a/drivers/tee/tee_core.c
+++ b/drivers/tee/tee_core.c
@@ -754,7 +754,7 @@ int tee_client_invoke_func(struct tee_context *ctx,
EXPORT_SYMBOL_GPL(tee_client_invoke_func);
static int tee_client_device_match(struct device *dev,
- struct device_driver *drv)
+ const struct device_driver *drv)
{
const struct tee_client_device_id *id_table;
struct tee_client_device *tee_device;
@@ -764,11 +764,11 @@ static int tee_client_device_match(struct device *dev,
while (!uuid_is_null(&id_table->uuid)) {
if (uuid_equal(&tee_device->id.uuid, &id_table->uuid))
- return 0;
+ return true;
id_table++;
}
- return -1;
+ return false;
}
struct bus_type tee_bus_type = {
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 6940476bb8b6..01d193d072fe 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -1178,10 +1178,10 @@ static const struct usb_device_id *usb_match_id(struct usb_device *usbdev,
}
EXPORT_SYMBOL(usb_match_id);
-static int usb_match(struct device *dev, struct driver *drv)
+static int usb_match(struct device *dev, const struct driver *drv)
{
struct usb_device *usbdev = container_of(dev, struct usb_device, dev);
- struct usb_driver *usbdrv = container_of(dev->driver, struct usb_driver, driver);
+ const struct usb_driver *usbdrv = container_of_const(drv, struct usb_driver, driver);
const struct usb_device_id *id;
pr_debug("matching: 0x%04x 0x%04x\n", usbdev->descriptor->idVendor,
@@ -1190,9 +1190,9 @@ static int usb_match(struct device *dev, struct driver *drv)
id = usb_match_id(usbdev, usbdrv->id_table);
if (id) {
pr_debug("match: 0x%04x 0x%04x\n", id->idVendor, id->idProduct);
- return 0;
+ return true;
}
- return 1;
+ return false;
}
static int usb_probe(struct device *dev)
diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index e7cfa0d5d836..4416902bc143 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -1344,24 +1344,24 @@ EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
/* ------------------------------------------------------------------------- */
-static int gadget_match_driver(struct device *dev, struct driver *drv)
+static int gadget_match_driver(struct device *dev, const struct driver *drv)
{
struct usb_gadget *gadget = dev_to_usb_gadget(dev);
struct usb_udc *udc = gadget->udc;
- struct usb_gadget_driver *driver = container_of(drv,
+ const struct usb_gadget_driver *driver = container_of_const(drv,
struct usb_gadget_driver, driver);
/* If the driver specifies a udc_name, it must match the UDC's name */
if (driver->udc_name &&
strcmp(driver->udc_name, dev_name(&udc->dev)) != 0)
- return -1;
+ return false;
/* If the driver is already bound to a gadget, it doesn't match */
if (driver->is_bound)
- return -1;
+ return false;
/* Otherwise any gadget driver matches any UDC */
- return 0;
+ return true;
}
static void udc_poll_driver(struct poller_struct *poller)
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index a0bd147c36c4..4abf551a2834 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -47,18 +47,18 @@ static inline int virtio_id_match(const struct virtio_device *dev,
/* This looks through all the IDs a driver claims to support. If any of them
* match, we return 1 and the kernel will call virtio_dev_probe(). */
-static int virtio_dev_match(struct device *_dv, struct driver *_dr)
+static int virtio_dev_match(struct device *_dv, const struct driver *_dr)
{
unsigned int i;
- struct virtio_device *dev = dev_to_virtio(_dv);
+ const struct virtio_device *dev = dev_to_virtio(_dv);
const struct virtio_device_id *ids;
ids = drv_to_virtio(_dr)->id_table;
for (i = 0; ids[i].device; i++)
if (virtio_id_match(dev, &ids[i]))
- return 0;
+ return true;
- return -1;
+ return false;
}
void virtio_check_driver_offered_feature(const struct virtio_device *vdev,
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index ac5fd3898276..15ada42ef0ba 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -362,12 +362,12 @@ int w1_reset_select_slave(struct w1_device *dev)
#define to_w1_device(d) container_of(d, struct w1_device, dev)
#define to_w1_driver(d) container_of(d, struct w1_driver, drv)
-static int w1_bus_match(struct device *_dev, struct driver *_drv)
+static int w1_bus_match(struct device *_dev, const struct driver *_drv)
{
- struct w1_device *dev = to_w1_device(_dev);
- struct w1_driver *drv = to_w1_driver(_drv);
+ const struct w1_device *dev = to_w1_device(_dev);
+ const struct w1_driver *drv = to_w1_driver(_drv);
- return !(drv->fid == dev->fid);
+ return drv->fid == dev->fid;
}
static int w1_bus_probe(struct device *_dev)
diff --git a/fs/fs.c b/fs/fs.c
index 400e85de102b..465fd617c2ba 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -762,9 +762,9 @@ int close(int fd)
}
EXPORT_SYMBOL(close);
-static int fs_match(struct device *dev, struct driver *drv)
+static int fs_match(struct device *dev, const struct driver *drv)
{
- return strcmp(dev->name, drv->name) ? -1 : 0;
+ return strcmp(dev->name, drv->name) == 0;
}
static int fs_probe(struct device *dev)
diff --git a/include/driver.h b/include/driver.h
index b63dce84c80e..b5f4de01e424 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -354,7 +354,7 @@ int generic_memmap_rw(struct cdev *dev, void **map, int flags);
struct bus_type {
char *name;
- int (*match)(struct device *dev, struct driver *drv);
+ int (*match)(struct device *dev, const struct driver *drv);
int (*probe)(struct device *dev);
void (*remove)(struct device *dev);
@@ -366,7 +366,13 @@ struct bus_type {
};
int bus_register(struct bus_type *bus);
-int device_match(struct device *dev, struct driver *drv);
+int device_match(struct device *dev, const struct driver *drv);
+
+static inline int driver_match_device(const struct driver *drv,
+ struct device *dev)
+{
+ return drv->bus->match ? drv->bus->match(dev, drv) : true;
+}
extern struct list_head bus_list;
@@ -674,7 +680,7 @@ int cdevfs_del_partition(struct cdev *cdev);
*/
const void *device_get_match_data(struct device *dev);
-int device_match_of_modalias(struct device *dev, struct driver *drv);
+int device_match_of_modalias(struct device *dev, const struct driver *drv);
struct device *device_find_child(struct device *parent, void *data,
int (*match)(struct device *dev, void *data));
diff --git a/include/of.h b/include/of.h
index 5829d9d1ace0..fccb8ba7e9e1 100644
--- a/include/of.h
+++ b/include/of.h
@@ -73,7 +73,7 @@ struct resource;
void of_fix_tree(struct device_node *);
-int of_match(struct device *dev, struct driver *drv);
+bool of_match(struct device *dev, const struct driver *drv);
int of_add_initrd(struct device_node *root, resource_size_t start,
resource_size_t end);
--
2.39.5
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/8] treewide: replace dev_get_drvdata with device_get_match_data
2025-05-06 6:34 [PATCH 1/8] treewide: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
` (6 preceding siblings ...)
2025-05-06 6:34 ` [PATCH 8/8] driver: base: invert driver match callback for Linux compatibility Ahmad Fatoum
@ 2025-05-06 7:41 ` Sascha Hauer
7 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2025-05-06 7:41 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Tue, 06 May 2025 08:34:39 +0200, Ahmad Fatoum wrote:
> Both Linux and barebox define a dev_get_drvdata function, but
> annoyingly, the barebox version accesses the private data set in the
> probe function, while the Linux version retrieves the match data set by
> the driver core instead.
>
> In preparation for changing the function to have the Linux semantics,
> start by replacing most instances in barebox with device_get_match_data.
>
> [...]
Applied, thanks!
[1/8] treewide: replace dev_get_drvdata with device_get_match_data
https://git.pengutronix.de/cgit/barebox/commit/?id=20d87123a638 (link may not be stable)
[2/8] ARM: i.MX: esdctl: replace dev_get_drvdata with device_get_match_data
https://git.pengutronix.de/cgit/barebox/commit/?id=443b268313cd (link may not be stable)
[3/8] driver: switch dev_get_drvdata to Linux semantics
https://git.pengutronix.de/cgit/barebox/commit/?id=d2ffe93877b9 (link may not be stable)
[4/8] gpio: gpio-mxs: replace dev_get_drvdata with device_get_match_data
https://git.pengutronix.de/cgit/barebox/commit/?id=0bac10a83bb9 (link may not be stable)
[5/8] mci: am654-sdhci: fix error code printed in error messages
https://git.pengutronix.de/cgit/barebox/commit/?id=aeefd448d91c (link may not be stable)
[6/8] pinctrl: at91: replace dev_get_drvdata with device_get_match_data
https://git.pengutronix.de/cgit/barebox/commit/?id=3142ec714275 (link may not be stable)
[7/8] drivers: maintain const when converting from struct driver
https://git.pengutronix.de/cgit/barebox/commit/?id=61c1bc52072d (link may not be stable)
[8/8] driver: base: invert driver match callback for Linux compatibility
https://git.pengutronix.de/cgit/barebox/commit/?id=64ca71016300 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 4/8] gpio: gpio-mxs: replace dev_get_drvdata with device_get_match_data
2025-05-06 6:34 ` [PATCH 4/8] gpio: gpio-mxs: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
@ 2025-05-06 7:42 ` Sascha Hauer
0 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2025-05-06 7:42 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Tue, May 06, 2025 at 08:34:42AM +0200, Ahmad Fatoum wrote:
> In preparation for aligning dev_get_drvdata with Linux, use
> device_get_match_data instead.
> While at it, we drop the unneeded struct mxs_gpio_chip::regs member to
> not have to worry about const safety.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> drivers/gpio/gpio-mxs.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
Moved this one and 5/8 before 3/8 while applying.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-05-06 7:47 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-06 6:34 [PATCH 1/8] treewide: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
2025-05-06 6:34 ` [PATCH 2/8] ARM: i.MX: esdctl: " Ahmad Fatoum
2025-05-06 6:34 ` [PATCH 3/8] driver: switch dev_get_drvdata to Linux semantics Ahmad Fatoum
2025-05-06 6:34 ` [PATCH 4/8] gpio: gpio-mxs: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
2025-05-06 7:42 ` Sascha Hauer
2025-05-06 6:34 ` [PATCH 5/8] mci: am654-sdhci: fix error code printed in error messages Ahmad Fatoum
2025-05-06 6:34 ` [PATCH 6/8] pinctrl: at91: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
2025-05-06 6:34 ` [PATCH 7/8] drivers: maintain const when converting from struct driver Ahmad Fatoum
2025-05-06 6:34 ` [PATCH 8/8] driver: base: invert driver match callback for Linux compatibility Ahmad Fatoum
2025-05-06 7:41 ` [PATCH 1/8] treewide: replace dev_get_drvdata with device_get_match_data Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox