Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mfd: arizona: Replace arizona_of_get_type() with device_get_match_data()

Replace the custom arizona_of_get_type() function with the generic
device_get_match_data() helper. Besides being a nice cleanup this
also makes it easier to add support for binding to ACPI enumerated
devices.

While at it also fix a possible NULL pointer deref of the id
argument to the probe functions (this could happen on e.g. manual
driver binding through sysfs).

Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>

authored by

Hans de Goede and committed by
Lee Jones
039da225 06e577b4

+12 -28
-11
drivers/mfd/arizona-core.c
··· 797 797 EXPORT_SYMBOL_GPL(arizona_pm_ops); 798 798 799 799 #ifdef CONFIG_OF 800 - unsigned long arizona_of_get_type(struct device *dev) 801 - { 802 - const struct of_device_id *id = of_match_device(arizona_of_match, dev); 803 - 804 - if (id) 805 - return (unsigned long)id->data; 806 - else 807 - return 0; 808 - } 809 - EXPORT_SYMBOL_GPL(arizona_of_get_type); 810 - 811 800 static int arizona_of_get_core_pdata(struct arizona *arizona) 812 801 { 813 802 struct arizona_pdata *pdata = &arizona->pdata;
+6 -4
drivers/mfd/arizona-i2c.c
··· 23 23 static int arizona_i2c_probe(struct i2c_client *i2c, 24 24 const struct i2c_device_id *id) 25 25 { 26 + const void *match_data; 26 27 struct arizona *arizona; 27 28 const struct regmap_config *regmap_config = NULL; 28 - unsigned long type; 29 + unsigned long type = 0; 29 30 int ret; 30 31 31 - if (i2c->dev.of_node) 32 - type = arizona_of_get_type(&i2c->dev); 33 - else 32 + match_data = device_get_match_data(&i2c->dev); 33 + if (match_data) 34 + type = (unsigned long)match_data; 35 + else if (id) 34 36 type = id->driver_data; 35 37 36 38 switch (type) {
+6 -4
drivers/mfd/arizona-spi.c
··· 23 23 static int arizona_spi_probe(struct spi_device *spi) 24 24 { 25 25 const struct spi_device_id *id = spi_get_device_id(spi); 26 + const void *match_data; 26 27 struct arizona *arizona; 27 28 const struct regmap_config *regmap_config = NULL; 28 - unsigned long type; 29 + unsigned long type = 0; 29 30 int ret; 30 31 31 - if (spi->dev.of_node) 32 - type = arizona_of_get_type(&spi->dev); 33 - else 32 + match_data = device_get_match_data(&spi->dev); 33 + if (match_data) 34 + type = (unsigned long)match_data; 35 + else if (id) 34 36 type = id->driver_data; 35 37 36 38 switch (type) {
-9
drivers/mfd/arizona.h
··· 50 50 int arizona_irq_init(struct arizona *arizona); 51 51 int arizona_irq_exit(struct arizona *arizona); 52 52 53 - #ifdef CONFIG_OF 54 - unsigned long arizona_of_get_type(struct device *dev); 55 - #else 56 - static inline unsigned long arizona_of_get_type(struct device *dev) 57 - { 58 - return 0; 59 - } 60 - #endif 61 - 62 53 #endif