Re: [PATCH 5/6 RESEND] mfd: arizona: Remove use of codec build config #ifdefs

From: Lee Jones
Date: Thu Oct 01 2015 - 07:45:09 EST


On Mon, 28 Sep 2015, Richard Fitzgerald wrote:

> Remove the use of #ifdefs around each case statement of the chip ID
> and type validation switches.
>
> We must ensure that the contained code still compiles to nothing if
> support for that codec was not built into the kernel, to prevent
> creation of link references to missing functions. So the ifdefs are
> replaced with a use of the IS_ENABLED() macro.
>
> Signed-off-by: Richard Fitzgerald <rf@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
> ---
> drivers/mfd/arizona-core.c | 29 +++++++++++++++++++++--------
> drivers/mfd/arizona-i2c.c | 28 +++++++++++++++-------------
> drivers/mfd/arizona-spi.c | 18 +++++++++++-------
> 3 files changed, 47 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c
> index 2512192..cc2117e 100644
> --- a/drivers/mfd/arizona-core.c
> +++ b/drivers/mfd/arizona-core.c
> @@ -1130,22 +1130,26 @@ int arizona_dev_init(struct arizona *arizona)
> arizona->rev &= ARIZONA_DEVICE_REVISION_MASK;
>
> switch (reg) {
> -#ifdef CONFIG_MFD_WM5102
> case 0x5102:
> + if (!IS_ENABLED(CONFIG_MFD_WM5102))
> + break;
> +

Are you sure this statement effects the code below?

I'm not sure it will. How have you tested it?

> type_name = "WM5102";
> if (arizona->type != WM5102) {
> dev_warn(arizona->dev, "WM5102 registered as %d\n",
> arizona->type);
> arizona->type = WM5102;
> }
> +
> apply_patch = wm5102_patch;
> arizona->rev &= 0x7;
> subdevs = wm5102_devs;
> n_subdevs = ARRAY_SIZE(wm5102_devs);
> break;
> -#endif
> -#ifdef CONFIG_MFD_WM5110
> case 0x5110:
> + if (!IS_ENABLED(CONFIG_MFD_WM5110))
> + break;
> +
> switch (arizona->type) {
> case WM5110:
> type_name = "WM5110";
> @@ -1160,26 +1164,30 @@ int arizona_dev_init(struct arizona *arizona)
> arizona->type = WM5110;
> break;
> }
> +
> apply_patch = wm5110_patch;
> subdevs = wm5110_devs;
> n_subdevs = ARRAY_SIZE(wm5110_devs);
> break;
> -#endif
> -#ifdef CONFIG_MFD_WM8997
> case 0x8997:
> + if (!IS_ENABLED(CONFIG_MFD_WM8997))
> + break;
> +
> type_name = "WM8997";
> if (arizona->type != WM8997) {
> dev_warn(arizona->dev, "WM8997 registered as %d\n",
> arizona->type);
> arizona->type = WM8997;
> }
> +
> apply_patch = wm8997_patch;
> subdevs = wm8997_devs;
> n_subdevs = ARRAY_SIZE(wm8997_devs);
> break;
> -#endif
> -#ifdef CONFIG_MFD_WM8998
> case 0x6349:
> + if (!IS_ENABLED(CONFIG_MFD_WM8998))
> + break;
> +
> switch (arizona->type) {
> case WM8998:
> type_name = "WM8998";
> @@ -1200,12 +1208,17 @@ int arizona_dev_init(struct arizona *arizona)
> subdevs = wm8998_devs;
> n_subdevs = ARRAY_SIZE(wm8998_devs);
> break;
> -#endif
> default:
> dev_err(arizona->dev, "Unknown device ID %x\n", reg);
> goto err_reset;
> }
>
> + if (!subdevs) {
> + dev_err(arizona->dev,
> + "No kernel support for device ID %x\n", reg);
> + goto err_reset;
> + }
> +
> dev_info(dev, "%s revision %c\n", type_name, arizona->rev + 'A');
>
> if (apply_patch) {
> diff --git a/drivers/mfd/arizona-i2c.c b/drivers/mfd/arizona-i2c.c
> index cea1b40..914bdce 100644
> --- a/drivers/mfd/arizona-i2c.c
> +++ b/drivers/mfd/arizona-i2c.c
> @@ -27,7 +27,7 @@ static int arizona_i2c_probe(struct i2c_client *i2c,
> const struct i2c_device_id *id)
> {
> struct arizona *arizona;
> - const struct regmap_config *regmap_config;
> + const struct regmap_config *regmap_config = NULL;
> unsigned long type;
> int ret;
>
> @@ -37,34 +37,36 @@ static int arizona_i2c_probe(struct i2c_client *i2c,
> type = id->driver_data;
>
> switch (type) {
> -#ifdef CONFIG_MFD_WM5102
> case WM5102:
> - regmap_config = &wm5102_i2c_regmap;
> + if (IS_ENABLED(CONFIG_MFD_WM5102))
> + regmap_config = &wm5102_i2c_regmap;
> break;
> -#endif
> -#ifdef CONFIG_MFD_WM5110
> case WM5110:
> case WM8280:
> - regmap_config = &wm5110_i2c_regmap;
> + if (IS_ENABLED(CONFIG_MFD_WM5110))
> + regmap_config = &wm5110_i2c_regmap;
> break;
> -#endif
> -#ifdef CONFIG_MFD_WM8997
> case WM8997:
> - regmap_config = &wm8997_i2c_regmap;
> + if (IS_ENABLED(CONFIG_MFD_WM8997))
> + regmap_config = &wm8997_i2c_regmap;
> break;
> -#endif
> -#ifdef CONFIG_MFD_WM8998
> case WM8998:
> case WM1814:
> - regmap_config = &wm8998_i2c_regmap;
> + if (IS_ENABLED(CONFIG_MFD_WM8998))
> + regmap_config = &wm8998_i2c_regmap;
> break;
> -#endif
> default:
> dev_err(&i2c->dev, "Unknown device type %ld\n",
> id->driver_data);
> return -EINVAL;
> }
>
> + if (!regmap_config) {
> + dev_err(&i2c->dev,
> + "No kernel support for device type %ld\n", type);
> + return -EINVAL;
> + }
> +
> arizona = devm_kzalloc(&i2c->dev, sizeof(*arizona), GFP_KERNEL);
> if (arizona == NULL)
> return -ENOMEM;
> diff --git a/drivers/mfd/arizona-spi.c b/drivers/mfd/arizona-spi.c
> index 1e845f6..850a63a 100644
> --- a/drivers/mfd/arizona-spi.c
> +++ b/drivers/mfd/arizona-spi.c
> @@ -27,7 +27,7 @@ static int arizona_spi_probe(struct spi_device *spi)
> {
> const struct spi_device_id *id = spi_get_device_id(spi);
> struct arizona *arizona;
> - const struct regmap_config *regmap_config;
> + const struct regmap_config *regmap_config = NULL;
> unsigned long type;
> int ret;
>
> @@ -37,23 +37,27 @@ static int arizona_spi_probe(struct spi_device *spi)
> type = id->driver_data;
>
> switch (type) {
> -#ifdef CONFIG_MFD_WM5102
> case WM5102:
> - regmap_config = &wm5102_spi_regmap;
> + if (IS_ENABLED(CONFIG_MFD_WM5102))
> + regmap_config = &wm5102_spi_regmap;
> break;
> -#endif
> -#ifdef CONFIG_MFD_WM5110
> case WM5110:
> case WM8280:
> - regmap_config = &wm5110_spi_regmap;
> + if (IS_ENABLED(CONFIG_MFD_WM5110))
> + regmap_config = &wm5110_spi_regmap;
> break;
> -#endif
> default:
> dev_err(&spi->dev, "Unknown device type %ld\n",
> id->driver_data);
> return -EINVAL;
> }
>
> + if (!regmap_config) {
> + dev_err(&spi->dev,
> + "No kernel support for device type %ld\n", type);
> + return -EINVAL;
> + }
> +
> arizona = devm_kzalloc(&spi->dev, sizeof(*arizona), GFP_KERNEL);
> if (arizona == NULL)
> return -ENOMEM;

--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org â Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/