Skip to contentSkip to conversation

mbox: qcom: avoid unused-variable warning

PATCH In review Arnd Bergmann 3 participants 7 messages Sep 20, 2019 – Oct 3, 2019 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mbox: qcom: avoid unused-variable warning

Without CONFIG_OF, there is no reference to the apcs_clk_match_table[] array, causing a harmless warning:

drivers/mailbox/qcom-apcs-ipc-mailbox.c:57:28: error: unused variable 'apcs_clk_match_table' [-Werror,-Wunused-variable]

        const struct of_device_id apcs_clk_match_table[] = {

Move the variable out of the variable scope and mark it 'static' to avoid the warning (static const variables get silently dropped by the compiler), and avoid the on-stack copy at the same time.

Fixes 78c86458a440 ("mbox: qcom: add APCS child device for QCS404")
---
 drivers/mailbox/qcom-apcs-ipc-mailbox.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/mailbox/qcom-apcs-ipc-mailbox.c +6 -5
index eeebafd546e5..10557a950c2d 100644
@@ -45,6 +45,12 @@ static const struct mbox_chan_ops qcom_apcs_ipc_ops = {
 	.send_data = qcom_apcs_ipc_send_data,
 };
 
+static const struct of_device_id apcs_clk_match_table[] = {
+	{ .compatible = "qcom,msm8916-apcs-kpss-global", },
+	{ .compatible = "qcom,qcs404-apcs-apps-global", },
+	{}
+};
+
 static int qcom_apcs_ipc_probe(struct platform_device *pdev)
 {
 	struct qcom_apcs_ipc *apcs;
@@ -54,11 +60,6 @@ static int qcom_apcs_ipc_probe(struct platform_device *pdev)
 	void __iomem *base;
 	unsigned long i;
 	int ret;
-	const struct of_device_id apcs_clk_match_table[] = {
-		{ .compatible = "qcom,msm8916-apcs-kpss-global", },
-		{ .compatible = "qcom,qcs404-apcs-apps-global", },
-		{}
-	};
 
 	apcs = devm_kzalloc(&pdev->dev, sizeof(*apcs), GFP_KERNEL);
 	if (!apcs)
Signature · 1 line
2.20.0
#1 lore raw

Quoting Arnd Bergmann (2019-09-20 07:55:29)

Quoted 34 lines

Without CONFIG_OF, there is no reference to the apcs_clk_match_table[] array, causing a harmless warning:

drivers/mailbox/qcom-apcs-ipc-mailbox.c:57:28: error: unused variable 'apcs_clk_match_table' [-Werror,-Wunused-variable]

        const struct of_device_id apcs_clk_match_table[] = {

Move the variable out of the variable scope and mark it 'static' to avoid the warning (static const variables get silently dropped by the compiler), and avoid the on-stack copy at the same time.

Fixes 78c86458a440 ("mbox: qcom: add APCS child device for QCS404")
---
 drivers/mailbox/qcom-apcs-ipc-mailbox.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/mailbox/qcom-apcs-ipc-mailbox.c +6 -0
index eeebafd546e5..10557a950c2d 100644
@@ -45,6 +45,12 @@ static const struct mbox_chan_ops qcom_apcs_ipc_ops = {
        .send_data = qcom_apcs_ipc_send_data,
 };
 
+static const struct of_device_id apcs_clk_match_table[] = {
+       { .compatible = "qcom,msm8916-apcs-kpss-global", },
+       { .compatible = "qcom,qcs404-apcs-apps-global", },
+       {}
+};
+
 static int qcom_apcs_ipc_probe(struct platform_device *pdev)
 {
        struct qcom_apcs_ipc *apcs;

drivers/mailbox/qcom-apcs-ipc-mailbox.c static int qcom_apcs_ipc_probe(struct platform_device *pdev) · line 57

Quoted 4 lines
drivers/mailbox/qcom-apcs-ipc-mailbox.c +0 -1
@@ -54,11 +60,6 @@ static int qcom_apcs_ipc_probe(struct platform_device *pdev)
        void __iomem *base;
        unsigned long i;
        int ret;
-       const struct of_device_id apcs_clk_match_table[] = {

Does marking it static here work too? It would be nice to limit the scope of this variable to this function instead of making it a global. Also, it might be slightly smaller code size if that works.

Quoted 7 lines
drivers/mailbox/qcom-apcs-ipc-mailbox.c +0 -4
-               { .compatible = "qcom,msm8916-apcs-kpss-global", },
-               { .compatible = "qcom,qcs404-apcs-apps-global", },
-               {}
-       };
 
        apcs = devm_kzalloc(&pdev->dev, sizeof(*apcs), GFP_KERNEL);
        if (!apcs)
#2 lore raw
Quoted 9 lines · Stephen Boyd

drivers/mailbox/qcom-apcs-ipc-mailbox.c static int qcom_apcs_ipc_probe(struct platform_device *pdev) · line 57

Quoted 5 lines
drivers/mailbox/qcom-apcs-ipc-mailbox.c +0 -1
@@ -54,11 +60,6 @@ static int qcom_apcs_ipc_probe(struct platform_device *pdev)
        void __iomem *base;
        unsigned long i;
        int ret;
-       const struct of_device_id apcs_clk_match_table[] = {

Does marking it static here work too? It would be nice to limit the scope of this variable to this function instead of making it a global. Also, it might be slightly smaller code size if that works.

No, I just tried and the warning returned.

Arnd

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Hi Stephen,

Quoted 13 lines · Stephen Boyd

Quoting Arnd Bergmann (2019-09-20 12:27:50)

Quoted 12 lines · Stephen Boyd
Quoted 9 lines

drivers/mailbox/qcom-apcs-ipc-mailbox.c static int qcom_apcs_ipc_probe(struct platform_device *pdev) · line 57

Quoted 5 lines
drivers/mailbox/qcom-apcs-ipc-mailbox.c +0 -1
@@ -54,11 +60,6 @@ static int qcom_apcs_ipc_probe(struct platform_device *pdev)
        void __iomem *base;
        unsigned long i;
        int ret;
-       const struct of_device_id apcs_clk_match_table[] = {

Does marking it static here work too? It would be nice to limit the scope of this variable to this function instead of making it a global. Also, it might be slightly smaller code size if that works.

No, I just tried and the warning returned.

It's there for the convenience for the user, so he doesn't have to add it himself explicitly.

Quoted 4 lines

("of/device: Nullify match table in of_match_device() for CONFIG_OF=n"), but it's been 5 years! Surely we can revert this change now that commit 219a7bc577e6 ("spi: rspi: Use of_device_get_match_data() helper") is merged.

Right, the particular error case in the RSPI driver can no longer happen.

Calling of_device_get_match_data() is the better solution anyway, as that uses the match table stored in dev->driver->of_match_table, so there's no need to pass the table explicitly, and conditionally.

Hence...

drivers/leds/leds-pca9532.c pca9532_of_populate_pdata(struct device *dev, struct device_node *np) · line 477

Quoted 10 lines
drivers/leds/leds-pca9532.c +1 -1
@@ -472,7 +472,7 @@ pca9532_of_populate_pdata(struct device *dev, struct device_node *np)
        int i = 0;
        const char *state;
 
-       match = of_match_device(of_pca9532_leds_match, dev);
+       match = of_match_device(of_match_ptr(of_pca9532_leds_match), dev);
        if (!match)
                return ERR_PTR(-ENODEV);

Please convert to of_device_get_match_data() instead of adding of_match_ptr() invocations...

drivers/leds/leds-pca9532.c static int pca9532_probe(struct i2c_client *client, · line 528

Quoted 6 lines
drivers/leds/leds-pca9532.c +1 -1
@@ -525,7 +525,7 @@ static int pca9532_probe(struct i2c_client *client,
                        dev_err(&client->dev, "no platform data\n");
                        return -EINVAL;
                }
-               of_id = of_match_device(of_pca9532_leds_match,
+               of_id = of_match_device(of_match_ptr(of_pca9532_leds_match),

Likewise.

sound/soc/jz4740/jz4740-i2s.c static int jz4740_i2s_dev_probe(struct platform_device *pdev) · line 506

Quoted 8 lines
sound/soc/jz4740/jz4740-i2s.c +1 -1
@@ -503,7 +503,7 @@ static int jz4740_i2s_dev_probe(struct platform_device *pdev)
        if (!i2s)
                return -ENOMEM;
 
-       match = of_match_device(jz4740_of_matches, &pdev->dev);
+       match = of_match_device(of_match_ptr(jz4740_of_matches), &pdev->dev);

Given of_device_get_match_data() returns NULL, not an error code, even this one could use of_device_get_match_data().

sound/soc/jz4740/jz4740-i2s.c static int jz4740_i2s_dev_probe(struct platform_device *pdev) · line 508

Quoted 2 lines
sound/soc/jz4740/jz4740-i2s.c +0 -0
        if (match)
                i2s->version = (enum jz47xx_i2s_version)match->data;

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#5 lore raw

Quoting Geert Uytterhoeven (2019-09-26 06:07:13)

Quoted 39 lines

Hi Stephen,

Quoted 13 lines · Stephen Boyd

Quoting Arnd Bergmann (2019-09-20 12:27:50)

Quoted 12 lines · Stephen Boyd
Quoted 9 lines

drivers/mailbox/qcom-apcs-ipc-mailbox.c static int qcom_apcs_ipc_probe(struct platform_device *pdev) · line 57

Quoted 5 lines
drivers/mailbox/qcom-apcs-ipc-mailbox.c +0 -1
@@ -54,11 +60,6 @@ static int qcom_apcs_ipc_probe(struct platform_device *pdev)
        void __iomem *base;
        unsigned long i;
        int ret;
-       const struct of_device_id apcs_clk_match_table[] = {

Does marking it static here work too? It would be nice to limit the scope of this variable to this function instead of making it a global. Also, it might be slightly smaller code size if that works.

No, I just tried and the warning returned.

It's there for the convenience for the user, so he doesn't have to add it himself explicitly.

Quoted 4 lines

("of/device: Nullify match table in of_match_device() for CONFIG_OF=n"), but it's been 5 years! Surely we can revert this change now that commit 219a7bc577e6 ("spi: rspi: Use of_device_get_match_data() helper") is merged.

Right, the particular error case in the RSPI driver can no longer happen.

Calling of_device_get_match_data() is the better solution anyway, as that uses the match table stored in dev->driver->of_match_table, so there's no need to pass the table explicitly, and conditionally.

Hence...

Quoted 6 lines
drivers/leds/leds-pca9532.c +0 -0
@@ -472,7 +472,7 @@ pca9532_of_populate_pdata(struct device *dev, struct device_node *np)
        int i = 0;
        const char *state;
 
Quoted 7 lines

drivers/leds/leds-pca9532.c pca9532_of_populate_pdata(struct device *dev, struct device_node *np) · line 477

Quoted 4 lines
drivers/leds/leds-pca9532.c +1 -1
-       match = of_match_device(of_pca9532_leds_match, dev);
+       match = of_match_device(of_match_ptr(of_pca9532_leds_match), dev);
        if (!match)
                return ERR_PTR(-ENODEV);

Please convert to of_device_get_match_data() instead of adding of_match_ptr() invocations...

How is this workable? I left it as of_match_device() because the value returned may be 0 for the enum and that looks the same as NULL.

Quoted 22 lines

drivers/leds/leds-pca9532.c static int pca9532_probe(struct i2c_client *client, · line 528

Quoted 7 lines
drivers/leds/leds-pca9532.c +1 -1
@@ -525,7 +525,7 @@ static int pca9532_probe(struct i2c_client *client,
                        dev_err(&client->dev, "no platform data\n");
                        return -EINVAL;
                }
-               of_id = of_match_device(of_pca9532_leds_match,
+               of_id = of_match_device(of_match_ptr(of_pca9532_leds_match),

Likewise.

sound/soc/jz4740/jz4740-i2s.c static int jz4740_i2s_dev_probe(struct platform_device *pdev) · line 506

Quoted 8 lines
sound/soc/jz4740/jz4740-i2s.c +1 -1
@@ -503,7 +503,7 @@ static int jz4740_i2s_dev_probe(struct platform_device *pdev)
        if (!i2s)
                return -ENOMEM;
 
-       match = of_match_device(jz4740_of_matches, &pdev->dev);
+       match = of_match_device(of_match_ptr(jz4740_of_matches), &pdev->dev);

Given of_device_get_match_data() returns NULL, not an error code, even this one could use of_device_get_match_data().

#6 lore raw

Hi Stephen,

Quoted 46 lines · Stephen Boyd

Quoting Geert Uytterhoeven (2019-09-26 06:07:13)

Quoted 37 lines · Stephen Boyd
Quoted 13 lines

Quoting Arnd Bergmann (2019-09-20 12:27:50)

Quoted 12 lines · Stephen Boyd
Quoted 9 lines

drivers/mailbox/qcom-apcs-ipc-mailbox.c static int qcom_apcs_ipc_probe(struct platform_device *pdev) · line 57

Quoted 5 lines
drivers/mailbox/qcom-apcs-ipc-mailbox.c +0 -1
@@ -54,11 +60,6 @@ static int qcom_apcs_ipc_probe(struct platform_device *pdev)
        void __iomem *base;
        unsigned long i;
        int ret;
-       const struct of_device_id apcs_clk_match_table[] = {

Does marking it static here work too? It would be nice to limit the scope of this variable to this function instead of making it a global. Also, it might be slightly smaller code size if that works.

No, I just tried and the warning returned.

It's there for the convenience for the user, so he doesn't have to add it himself explicitly.

Quoted 4 lines

("of/device: Nullify match table in of_match_device() for CONFIG_OF=n"), but it's been 5 years! Surely we can revert this change now that commit 219a7bc577e6 ("spi: rspi: Use of_device_get_match_data() helper") is merged.

Right, the particular error case in the RSPI driver can no longer happen.

Calling of_device_get_match_data() is the better solution anyway, as that uses the match table stored in dev->driver->of_match_table, so there's no need to pass the table explicitly, and conditionally.

Hence...

Quoted 6 lines
drivers/leds/leds-pca9532.c +0 -0
@@ -472,7 +472,7 @@ pca9532_of_populate_pdata(struct device *dev, struct device_node *np)
        int i = 0;
        const char *state;
 
Quoted 7 lines

drivers/leds/leds-pca9532.c pca9532_of_populate_pdata(struct device *dev, struct device_node *np) · line 477

Quoted 4 lines
drivers/leds/leds-pca9532.c +1 -1
-       match = of_match_device(of_pca9532_leds_match, dev);
+       match = of_match_device(of_match_ptr(of_pca9532_leds_match), dev);
        if (!match)
                return ERR_PTR(-ENODEV);

Please convert to of_device_get_match_data() instead of adding of_match_ptr() invocations...

Quoted 2 lines

How is this workable? I left it as of_match_device() because the value returned may be 0 for the enum and that looks the same as NULL.

This function is used for the DT case only, so there will always be a match. Hence you can do devid = (int)(uintptr_t)of_device_get_match_data(dev).

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#7 lore raw

Quoting Geert Uytterhoeven (2019-09-27 12:10:13)

Quoted 20 lines · Stephen Boyd
Quoted 19 lines

Quoting Geert Uytterhoeven (2019-09-26 06:07:13)

Quoted 17 lines · Stephen Boyd

drivers/leds/leds-pca9532.c pca9532_of_populate_pdata(struct device *dev, struct device_node *np) · line 477

Quoted 13 lines

Quoting Arnd Bergmann (2019-09-20 12:27:50)

Quoted 1 line · Stephen Boyd
drivers/leds/leds-pca9532.c +1 -1
@@ -472,7 +472,7 @@ pca9532_of_populate_pdata(struct device *dev, struct device_node *np)
        int i = 0;
        const char *state;
 
-       match = of_match_device(of_pca9532_leds_match, dev);
+       match = of_match_device(of_match_ptr(of_pca9532_leds_match), dev);
        if (!match)
                return ERR_PTR(-ENODEV);

Please convert to of_device_get_match_data() instead of adding of_match_ptr() invocations...

Quoted 6 lines
Quoted 2 lines

How is this workable? I left it as of_match_device() because the value returned may be 0 for the enum and that looks the same as NULL.

This function is used for the DT case only, so there will always be a match. Hence you can do devid = (int)(uintptr_t)of_device_get_match_data(dev).

Ok. Let me send out a pile of patches.