Skip to contentSkip to conversation

Address some clang W=1 warnings

PATCH In review Mauro Carvalho Chehab 2 participants 15 messages Nov 22, 2021 – Nov 29, 2021

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

cover Address some clang W=1 warnings

Clang is more pedantic than gcc with W=1. This is currently causing builder.linuxtv.org errors due to CONFIG_WERROR.

Address some of those.

Mauro Carvalho Chehab (10):
media: cx25821: drop duplicated i2c_slave_did_ack()
media: ivtv: drop an unused macro
media: cx18: drop an unused macro
media: stb6100: mark a currently unused function as such
media: mc: mark a debug function with __maybe_unused
media: dvb-core: dvb_frontend: address some clang warnings
media: cx25840: drop some unused inline functions
media: marvell-ccic: drop to_cam() unused function
media: omap3isp: mark isp_isr_dbg as __maybe_unused
media: omap3isp: avoid warnings at IS_OUT_OF_BOUNDS()

 drivers/media/dvb-core/dvb_frontend.c         | 13 +++++-------
 drivers/media/dvb-frontends/stb6100.c         |  2 +-
 drivers/media/i2c/cx25840/cx25840-ir.c        | 20 -------------------
 drivers/media/mc/mc-entity.c                  |  2 +-
 drivers/media/pci/cx18/cx18-alsa-main.c       |  6 ------
 drivers/media/pci/cx25821/cx25821-core.c      |  7 -------
 drivers/media/pci/ivtv/ivtv-alsa-main.c       |  6 ------
 .../media/platform/marvell-ccic/cafe-driver.c |  7 -------
 drivers/media/platform/omap3isp/isp.c         |  3 ++-
 drivers/media/platform/omap3isp/isph3a_af.c   |  2 +-
 10 files changed, 10 insertions(+), 58 deletions(-)
Signature · 1 line
2.33.1
#1 lore raw

PATCH 1/10 media: cx25821: drop duplicated i2c_slave_did_ack()

This function is defined twice, one at cx25821-i2c and the other inside cx25821-core. It turns that only the first
is actually used inside the code.

This causes a clang warning.

---

To avoid mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH 00/10] at: https://lore.kernel.org/all/[email protected]/

 drivers/media/pci/cx25821/cx25821-core.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/media/pci/cx25821/cx25821-core.c +0 -7
index 40c10ca94def..3078a39f0b95 100644
@@ -337,13 +337,6 @@ static int cx25821_risc_decode(u32 risc)
 	return incr[risc >> 28] ? incr[risc >> 28] : 1;
 }
 
-static inline int i2c_slave_did_ack(struct i2c_adapter *i2c_adap)
-{
-	struct cx25821_i2c *bus = i2c_adap->algo_data;
-	struct cx25821_dev *dev = bus->dev;
-	return cx_read(bus->reg_stat) & 0x01;
-}
-
 static void cx25821_registers_init(struct cx25821_dev *dev)
 {
 	u32 tmp;
Signature · 1 line
2.33.1
#2 lore raw

PATCH 2/10 media: ivtv: drop an unused macro

In reply to Mauro Carvalho Chehab

The macro p_to_snd_ivtv_card() is just a variant for container_of(), not actually used inside the code. So, drop it.

This address a clang warning.

---

To avoid mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH 00/10] at: https://lore.kernel.org/all/[email protected]/

 drivers/media/pci/ivtv/ivtv-alsa-main.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/media/pci/ivtv/ivtv-alsa-main.c +0 -6
index 4cefdb2e4d40..9e13a7128a53 100644
@@ -48,12 +48,6 @@ struct snd_ivtv_card *to_snd_ivtv_card(struct v4l2_device *v4l2_dev)
 	return to_ivtv(v4l2_dev)->alsa;
 }
 
-static inline
-struct snd_ivtv_card *p_to_snd_ivtv_card(struct v4l2_device **v4l2_dev)
-{
-	return container_of(v4l2_dev, struct snd_ivtv_card, v4l2_dev);
-}
-
 static void snd_ivtv_card_free(struct snd_ivtv_card *itvsc)
 {
 	if (itvsc == NULL)
Signature · 1 line
2.33.1
#3 lore raw

PATCH 3/10 media: cx18: drop an unused macro

In reply to Mauro Carvalho Chehab

The macro p_to_snd_cx18_card() is just a variant for container_of(), not actually used inside the code. So, drop it.

This address a clang warning.

---

To avoid mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH 00/10] at: https://lore.kernel.org/all/[email protected]/

 drivers/media/pci/cx18/cx18-alsa-main.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/media/pci/cx18/cx18-alsa-main.c +0 -6
index 9a82e68303b6..9dc361886284 100644
@@ -51,12 +51,6 @@ struct snd_cx18_card *to_snd_cx18_card(struct v4l2_device *v4l2_dev)
 	return to_cx18(v4l2_dev)->alsa;
 }
 
-static inline
-struct snd_cx18_card *p_to_snd_cx18_card(struct v4l2_device **v4l2_dev)
-{
-	return container_of(v4l2_dev, struct snd_cx18_card, v4l2_dev);
-}
-
 static void snd_cx18_card_free(struct snd_cx18_card *cxsc)
 {
 	if (cxsc == NULL)
Signature · 1 line
2.33.1
#4 lore raw

PATCH 4/10 media: stb6100: mark a currently unused function as such

In reply to Mauro Carvalho Chehab

The stb6100_normalise_regs() function is not used with current boards, but the driver says that some devices could need it. Ok, we could simply drop it, but as there's a macro to mark unused functions, use it.

This should shut up a clang warning.

---

To avoid mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH 00/10] at: https://lore.kernel.org/all/[email protected]/

 drivers/media/dvb-frontends/stb6100.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/dvb-frontends/stb6100.c +1 -1
index d541d6613610..ea1d260e4d70 100644
@@ -110,7 +110,7 @@ static const struct stb6100_regmask stb6100_template[] = {
 /*
  * Currently unused. Some boards might need it in the future
  */
-static inline void stb6100_normalise_regs(u8 regs[])
+static __maybe_unused inline void stb6100_normalise_regs(u8 regs[])
 {
 	int i;
 
Signature · 1 line
2.33.1
#5 lore raw

PATCH 5/10 media: mc: mark a debug function with __maybe_unused

In reply to Mauro Carvalho Chehab

The gobj_type() function translates the media object type into a name, being useful for debugging purposes. It is currently not used, but let's keep it around, as it can be useful.

So, mark it with __maybe_unused, in order to shut up a clang warning.

---

To avoid mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH 00/10] at: https://lore.kernel.org/all/[email protected]/

 drivers/media/mc/mc-entity.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/mc/mc-entity.c +1 -1
index f40f41977142..b0ea145ac9c0 100644
@@ -14,7 +14,7 @@
 #include <media/media-entity.h>
 #include <media/media-device.h>
 
-static inline const char *gobj_type(enum media_gobj_type type)
+static inline __maybe_unused const char *gobj_type(enum media_gobj_type type)
 {
 	switch (type) {
 	case MEDIA_GRAPH_ENTITY:
Signature · 1 line
2.33.1
maintainer
#6 lore raw

Re: [PATCH 05/10] media: mc: mark a debug function with __maybe_unused

Hi Mauro,

Thank you for the patch.

Quoted 3 lines · Mauro Carvalho Chehab

The gobj_type() function translates the media object type into a name, being useful for debugging purposes. It is currently not used, but let's keep it around, as it can be useful.

Don't we usually remove dead code, and add it back later when and if needed, unless we know the code will be used in the near future ? I don't care too much either way.

Quoted 25 lines

So, mark it with __maybe_unused, in order to shut up a clang warning.

---

To avoid mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH 00/10] at: https://lore.kernel.org/all/[email protected]/

 drivers/media/mc/mc-entity.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/mc/mc-entity.c +1 -1
index f40f41977142..b0ea145ac9c0 100644
@@ -14,7 +14,7 @@
 #include <media/media-entity.h>
 #include <media/media-device.h>
 
-static inline const char *gobj_type(enum media_gobj_type type)
+static inline __maybe_unused const char *gobj_type(enum media_gobj_type type)
 {
 	switch (type) {
 	case MEDIA_GRAPH_ENTITY:
Signature · 3 lines
Regards,

Laurent Pinchart
#7 lore raw

PATCH 6/10 media: dvb-core: dvb_frontend: address some clang warnings

In reply to Mauro Carvalho Chehab

The typecasts at the dvb-core generate clang warnings when W=1 is enabled.

The warns are harmless, but they cause the build to break with CONFIG_WERROR, so do the cast on a way that it won't produce warnings anymore.

---

To avoid mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH 00/10] at: https://lore.kernel.org/all/[email protected]/

 drivers/media/dvb-core/dvb_frontend.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/media/dvb-core/dvb_frontend.c +5 -8
index 8fc59f3cfb6c..48e735cdbe6b 100644
@@ -2554,8 +2554,7 @@ static int dvb_frontend_handle_ioctl(struct file *file,
 
 	case FE_DISEQC_SEND_BURST:
 		if (fe->ops.diseqc_send_burst) {
-			err = fe->ops.diseqc_send_burst(fe,
-						(enum fe_sec_mini_cmd)parg);
+			err = fe->ops.diseqc_send_burst(fe, (long)parg);
 			fepriv->state = FESTATE_DISEQC;
 			fepriv->status = 0;
 		}
@@ -2563,9 +2562,8 @@ static int dvb_frontend_handle_ioctl(struct file *file,
 
 	case FE_SET_TONE:
 		if (fe->ops.set_tone) {
-			err = fe->ops.set_tone(fe,
-					       (enum fe_sec_tone_mode)parg);
-			fepriv->tone = (enum fe_sec_tone_mode)parg;
+			fepriv->tone = (long)parg;
+			err = fe->ops.set_tone(fe, fepriv->tone);
 			fepriv->state = FESTATE_DISEQC;
 			fepriv->status = 0;
 		}
@@ -2573,9 +2571,8 @@ static int dvb_frontend_handle_ioctl(struct file *file,
 
 	case FE_SET_VOLTAGE:
 		if (fe->ops.set_voltage) {
-			err = fe->ops.set_voltage(fe,
-						  (enum fe_sec_voltage)parg);
-			fepriv->voltage = (enum fe_sec_voltage)parg;
+			fepriv->voltage = (long)parg;
+			err = fe->ops.set_voltage(fe, fepriv->voltage);
 			fepriv->state = FESTATE_DISEQC;
 			fepriv->status = 0;
 		}
Signature · 1 line
2.33.1
#8 lore raw

PATCH 7/10 media: cx25840: drop some unused inline functions

In reply to Mauro Carvalho Chehab

Solve some clang warnings about unused functions by dropping some time-conversion inline funcs that aren't used anywhere.

---

To avoid mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH 00/10] at: https://lore.kernel.org/all/[email protected]/

 drivers/media/i2c/cx25840/cx25840-ir.c | 20 --------------------
 1 file changed, 20 deletions(-)
drivers/media/i2c/cx25840/cx25840-ir.c +0 -20
index 2cf3e6a1f9e1..9d7d1d149f1a 100644
@@ -136,19 +136,6 @@ static inline u16 count_to_clock_divider(unsigned int d)
 	return (u16) d;
 }
 
-static inline u16 ns_to_clock_divider(unsigned int ns)
-{
-	return count_to_clock_divider(
-		DIV_ROUND_CLOSEST(CX25840_IR_REFCLK_FREQ / 1000000 * ns, 1000));
-}
-
-static inline unsigned int clock_divider_to_ns(unsigned int divider)
-{
-	/* Period of the Rx or Tx clock in ns */
-	return DIV_ROUND_CLOSEST((divider + 1) * 1000,
-				 CX25840_IR_REFCLK_FREQ / 1000000);
-}
-
 static inline u16 carrier_freq_to_clock_divider(unsigned int freq)
 {
 	return count_to_clock_divider(
@@ -160,13 +147,6 @@ static inline unsigned int clock_divider_to_carrier_freq(unsigned int divider)
 	return DIV_ROUND_CLOSEST(CX25840_IR_REFCLK_FREQ, (divider + 1) * 16);
 }
 
-static inline u16 freq_to_clock_divider(unsigned int freq,
-					unsigned int rollovers)
-{
-	return count_to_clock_divider(
-		   DIV_ROUND_CLOSEST(CX25840_IR_REFCLK_FREQ, freq * rollovers));
-}
-
 static inline unsigned int clock_divider_to_freq(unsigned int divider,
 						 unsigned int rollovers)
 {
Signature · 1 line
2.33.1
#9 lore raw

PATCH 8/10 media: marvell-ccic: drop to_cam() unused function

In reply to Mauro Carvalho Chehab

This function is an alias for container_of() that it is currently not used, causing clang warnings. So, drop it.

---

To avoid mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH 00/10] at: https://lore.kernel.org/all/[email protected]/

 drivers/media/platform/marvell-ccic/cafe-driver.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/media/platform/marvell-ccic/cafe-driver.c +0 -7
index b61b9d9551af..03dcf8bf705e 100644
@@ -139,13 +139,6 @@ struct cafe_camera {
  */
 #define CAFE_SMBUS_TIMEOUT (HZ)  /* generous */
 
-static inline struct cafe_camera *to_cam(struct v4l2_device *dev)
-{
-	struct mcam_camera *m = container_of(dev, struct mcam_camera, v4l2_dev);
-	return container_of(m, struct cafe_camera, mcam);
-}
-
-
 static int cafe_smbus_write_done(struct mcam_camera *mcam)
 {
 	unsigned long flags;
Signature · 1 line
2.33.1
#10 lore raw

PATCH 9/10 media: omap3isp: mark isp_isr_dbg as __maybe_unused

In reply to Mauro Carvalho Chehab

This function is only used for debugging purposes. When DEBUG is disabled, it becomes unused, causing a clang warning with W=1.

---

To avoid mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH 00/10] at: https://lore.kernel.org/all/[email protected]/

 drivers/media/platform/omap3isp/isp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/omap3isp/isp.c +2 -1
index 6de377ce281d..4c937f3f323e 100644
@@ -476,7 +476,8 @@ void omap3isp_hist_dma_done(struct isp_device *isp)
 	}
 }
 
-static inline void isp_isr_dbg(struct isp_device *isp, u32 irqstatus)
+static inline void __maybe_unused isp_isr_dbg(struct isp_device *isp,
+					      u32 irqstatus)
 {
 	static const char *name[] = {
 		"CSIA_IRQ",
Signature · 1 line
2.33.1
maintainer Reviewed-by on v1 9/10
#11 lore raw

Re: [PATCH 09/10] media: omap3isp: mark isp_isr_dbg as __maybe_unused

Hi Mauro,

Thank you for the patch.

Quoted 4 lines · Mauro Carvalho Chehab

This function is only used for debugging purposes. When DEBUG is disabled, it becomes unused, causing a clang warning with W=1.

Quoted 22 lines

---

To avoid mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH 00/10] at: https://lore.kernel.org/all/[email protected]/

 drivers/media/platform/omap3isp/isp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/omap3isp/isp.c +2 -1
index 6de377ce281d..4c937f3f323e 100644
@@ -476,7 +476,8 @@ void omap3isp_hist_dma_done(struct isp_device *isp)
 	}
 }
 
-static inline void isp_isr_dbg(struct isp_device *isp, u32 irqstatus)
+static inline void __maybe_unused isp_isr_dbg(struct isp_device *isp,
+					      u32 irqstatus)
 {
 	static const char *name[] = {
 		"CSIA_IRQ",
Signature · 3 lines
Regards,

Laurent Pinchart
#12 lore raw

PATCH v2 9/10 media: mc: drop an unused debug function

The gobj_type() function translates the media object type into a name, being useful for debugging purposes. It is currently not used. So, drop it.

---
 drivers/media/mc/mc-entity.c | 16 ----------------
 1 file changed, 16 deletions(-)
drivers/media/mc/mc-entity.c +0 -16
index f40f41977142..c02340698ad6 100644
@@ -14,22 +14,6 @@
 #include <media/media-entity.h>
 #include <media/media-device.h>
 
-static inline const char *gobj_type(enum media_gobj_type type)
-{
-	switch (type) {
-	case MEDIA_GRAPH_ENTITY:
-		return "entity";
-	case MEDIA_GRAPH_PAD:
-		return "pad";
-	case MEDIA_GRAPH_LINK:
-		return "link";
-	case MEDIA_GRAPH_INTF_DEVNODE:
-		return "intf-devnode";
-	default:
-		return "unknown";
-	}
-}
-
 static inline const char *intf_type(struct media_interface *intf)
 {
 	switch (intf->type) {
Signature · 1 line
2.33.1
#13 lore raw

PATCH 10/10 media: omap3isp: avoid warnings at IS_OUT_OF_BOUNDS()

In reply to Mauro Carvalho Chehab

Clang with W=1 produces the following warnings:

drivers/media/platform/omap3isp/isph3a_af.c:173:6: error: result of comparison of constant 256 with expression of type '__u8' (aka 'unsigned char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]

        if (IS_OUT_OF_BOUNDS(paxel_cfg->height, OMAP3ISP_AF_PAXEL_HEIGHT_MIN,
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/omap3isp/isph3a_af.c:24:33: note: expanded from macro 'IS_OUT_OF_BOUNDS'
        (((value) < (min)) || ((value) > (max)))
                               ~~~~~~~ ^ ~~~~~
drivers/media/platform/omap3isp/isph3a_af.c:179:6: error: result of comparison of constant 256 with expression of type '__u8' (aka 'unsigned char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
        if (IS_OUT_OF_BOUNDS(paxel_cfg->width, OMAP3ISP_AF_PAXEL_WIDTH_MIN,
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/omap3isp/isph3a_af.c:24:33: note: expanded from macro 'IS_OUT_OF_BOUNDS'
        (((value) < (min)) || ((value) > (max)))
                               ~~~~~~~ ^ ~~~~~

2 errors generated.

Use a typecast to avoid such warnings.

---

To avoid mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH 00/10] at: https://lore.kernel.org/all/[email protected]/

 drivers/media/platform/omap3isp/isph3a_af.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/omap3isp/isph3a_af.c +1 -1
index a65cfdfa9637..de7b116d0122 100644
@@ -21,7 +21,7 @@
 #include "ispstat.h"
 
 #define IS_OUT_OF_BOUNDS(value, min, max)		\
-	(((value) < (min)) || ((value) > (max)))
+	((((unsigned int)value) < (min)) || (((unsigned int)value) > (max)))
 
 static void h3a_af_setup_regs(struct ispstat *af, void *priv)
 {
Signature · 1 line
2.33.1
maintainer Reviewed-by on v1 10/10
#14 lore raw

Re: [PATCH 10/10] media: omap3isp: avoid warnings at IS_OUT_OF_BOUNDS()

Hi Mauro,

Thank you for the patch.

Quoted 32 lines · Mauro Carvalho Chehab

Clang with W=1 produces the following warnings:

drivers/media/platform/omap3isp/isph3a_af.c:173:6: error: result of comparison of constant 256 with expression of type '__u8' (aka 'unsigned char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]

        if (IS_OUT_OF_BOUNDS(paxel_cfg->height, OMAP3ISP_AF_PAXEL_HEIGHT_MIN,
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/omap3isp/isph3a_af.c:24:33: note: expanded from macro 'IS_OUT_OF_BOUNDS'
        (((value) < (min)) || ((value) > (max)))
                               ~~~~~~~ ^ ~~~~~
drivers/media/platform/omap3isp/isph3a_af.c:179:6: error: result of comparison of constant 256 with expression of type '__u8' (aka 'unsigned char') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
        if (IS_OUT_OF_BOUNDS(paxel_cfg->width, OMAP3ISP_AF_PAXEL_WIDTH_MIN,
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/media/platform/omap3isp/isph3a_af.c:24:33: note: expanded from macro 'IS_OUT_OF_BOUNDS'
        (((value) < (min)) || ((value) > (max)))
                               ~~~~~~~ ^ ~~~~~

2 errors generated.

Use a typecast to avoid such warnings.

---

To avoid mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH 00/10] at: https://lore.kernel.org/all/[email protected]/

 drivers/media/platform/omap3isp/isph3a_af.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/omap3isp/isph3a_af.c +0 -0
index a65cfdfa9637..de7b116d0122 100644

drivers/media/platform/omap3isp/isph3a_af.c line 24

Quoted 5 lines
drivers/media/platform/omap3isp/isph3a_af.c +1 -1
@@ -21,7 +21,7 @@
 #include "ispstat.h"
 
 #define IS_OUT_OF_BOUNDS(value, min, max)		\
-	(((value) < (min)) || ((value) > (max)))
+	((((unsigned int)value) < (min)) || (((unsigned int)value) > (max)))

It could have been a good occasion to replace the macro with an inline function.

Quoted 3 lines
drivers/media/platform/omap3isp/isph3a_af.c +0 -0
 static void h3a_af_setup_regs(struct ispstat *af, void *priv)
 {
Signature · 3 lines
Regards,

Laurent Pinchart