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

ASoC: max980*: use i2c_match_id and simple i2c probe

As part of the ongoing i2c transition to the simple probe
("probe_new"), this patch uses i2c_match_id to retrieve the
driver_data for the probed device. The id parameter is thus no longer
necessary and the simple probe can be used instead.

In the context of an i2c probe, i2c_match_id with the module id table
and the probed client never returns null, so removing the null check
on the i2c_device_id pointer is safe.

The i2c id tables are moved up before the probe function, as
suggested by Wolfram Sang.

Signed-off-by: Stephen Kitt <steve@sk2.org>
Link: https://lore.kernel.org/r/20220415160613.148882-4-steve@sk2.org
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Stephen Kitt and committed by
Mark Brown
4ac8ebb6 9d8f2edd

+33 -30
+11 -10
sound/soc/codecs/max98088.c
··· 1737 1737 .non_legacy_dai_naming = 1, 1738 1738 }; 1739 1739 1740 - static int max98088_i2c_probe(struct i2c_client *i2c, 1741 - const struct i2c_device_id *id) 1740 + static const struct i2c_device_id max98088_i2c_id[] = { 1741 + { "max98088", MAX98088 }, 1742 + { "max98089", MAX98089 }, 1743 + { } 1744 + }; 1745 + MODULE_DEVICE_TABLE(i2c, max98088_i2c_id); 1746 + 1747 + static int max98088_i2c_probe(struct i2c_client *i2c) 1742 1748 { 1743 1749 struct max98088_priv *max98088; 1744 1750 int ret; 1751 + const struct i2c_device_id *id; 1745 1752 1746 1753 max98088 = devm_kzalloc(&i2c->dev, sizeof(struct max98088_priv), 1747 1754 GFP_KERNEL); ··· 1764 1757 if (PTR_ERR(max98088->mclk) == -EPROBE_DEFER) 1765 1758 return PTR_ERR(max98088->mclk); 1766 1759 1760 + id = i2c_match_id(max98088_i2c_id, i2c); 1767 1761 max98088->devtype = id->driver_data; 1768 1762 1769 1763 i2c_set_clientdata(i2c, max98088); ··· 1774 1766 &soc_component_dev_max98088, &max98088_dai[0], 2); 1775 1767 return ret; 1776 1768 } 1777 - 1778 - static const struct i2c_device_id max98088_i2c_id[] = { 1779 - { "max98088", MAX98088 }, 1780 - { "max98089", MAX98089 }, 1781 - { } 1782 - }; 1783 - MODULE_DEVICE_TABLE(i2c, max98088_i2c_id); 1784 1769 1785 1770 #if defined(CONFIG_OF) 1786 1771 static const struct of_device_id max98088_of_match[] = { ··· 1789 1788 .name = "max98088", 1790 1789 .of_match_table = of_match_ptr(max98088_of_match), 1791 1790 }, 1792 - .probe = max98088_i2c_probe, 1791 + .probe_new = max98088_i2c_probe, 1793 1792 .id_table = max98088_i2c_id, 1794 1793 }; 1795 1794
+12 -11
sound/soc/codecs/max98090.c
··· 2529 2529 .cache_type = REGCACHE_RBTREE, 2530 2530 }; 2531 2531 2532 - static int max98090_i2c_probe(struct i2c_client *i2c, 2533 - const struct i2c_device_id *i2c_id) 2532 + static const struct i2c_device_id max98090_i2c_id[] = { 2533 + { "max98090", MAX98090 }, 2534 + { "max98091", MAX98091 }, 2535 + { } 2536 + }; 2537 + MODULE_DEVICE_TABLE(i2c, max98090_i2c_id); 2538 + 2539 + static int max98090_i2c_probe(struct i2c_client *i2c) 2534 2540 { 2535 2541 struct max98090_priv *max98090; 2536 2542 const struct acpi_device_id *acpi_id; ··· 2558 2552 return -EINVAL; 2559 2553 } 2560 2554 driver_data = acpi_id->driver_data; 2561 - } else if (i2c_id) { 2555 + } else { 2556 + const struct i2c_device_id *i2c_id = 2557 + i2c_match_id(max98090_i2c_id, i2c); 2562 2558 driver_data = i2c_id->driver_data; 2563 2559 } 2564 2560 ··· 2667 2659 SET_SYSTEM_SLEEP_PM_OPS(NULL, max98090_resume) 2668 2660 }; 2669 2661 2670 - static const struct i2c_device_id max98090_i2c_id[] = { 2671 - { "max98090", MAX98090 }, 2672 - { "max98091", MAX98091 }, 2673 - { } 2674 - }; 2675 - MODULE_DEVICE_TABLE(i2c, max98090_i2c_id); 2676 - 2677 2662 #ifdef CONFIG_OF 2678 2663 static const struct of_device_id max98090_of_match[] = { 2679 2664 { .compatible = "maxim,max98090", }, ··· 2691 2690 .of_match_table = of_match_ptr(max98090_of_match), 2692 2691 .acpi_match_table = ACPI_PTR(max98090_acpi_match), 2693 2692 }, 2694 - .probe = max98090_i2c_probe, 2693 + .probe_new = max98090_i2c_probe, 2695 2694 .shutdown = max98090_i2c_shutdown, 2696 2695 .remove = max98090_i2c_remove, 2697 2696 .id_table = max98090_i2c_id,
+10 -9
sound/soc/codecs/max98095.c
··· 2106 2106 .non_legacy_dai_naming = 1, 2107 2107 }; 2108 2108 2109 - static int max98095_i2c_probe(struct i2c_client *i2c, 2110 - const struct i2c_device_id *id) 2109 + static const struct i2c_device_id max98095_i2c_id[] = { 2110 + { "max98095", MAX98095 }, 2111 + { } 2112 + }; 2113 + MODULE_DEVICE_TABLE(i2c, max98095_i2c_id); 2114 + 2115 + static int max98095_i2c_probe(struct i2c_client *i2c) 2111 2116 { 2112 2117 struct max98095_priv *max98095; 2113 2118 int ret; 2119 + const struct i2c_device_id *id; 2114 2120 2115 2121 max98095 = devm_kzalloc(&i2c->dev, sizeof(struct max98095_priv), 2116 2122 GFP_KERNEL); ··· 2132 2126 return ret; 2133 2127 } 2134 2128 2129 + id = i2c_match_id(max98095_i2c_id, i2c); 2135 2130 max98095->devtype = id->driver_data; 2136 2131 i2c_set_clientdata(i2c, max98095); 2137 2132 max98095->pdata = i2c->dev.platform_data; ··· 2142 2135 max98095_dai, ARRAY_SIZE(max98095_dai)); 2143 2136 return ret; 2144 2137 } 2145 - 2146 - static const struct i2c_device_id max98095_i2c_id[] = { 2147 - { "max98095", MAX98095 }, 2148 - { } 2149 - }; 2150 - MODULE_DEVICE_TABLE(i2c, max98095_i2c_id); 2151 2138 2152 2139 #ifdef CONFIG_OF 2153 2140 static const struct of_device_id max98095_of_match[] = { ··· 2156 2155 .name = "max98095", 2157 2156 .of_match_table = of_match_ptr(max98095_of_match), 2158 2157 }, 2159 - .probe = max98095_i2c_probe, 2158 + .probe_new = max98095_i2c_probe, 2160 2159 .id_table = max98095_i2c_id, 2161 2160 }; 2162 2161