Skip to contentSkip to conversation

rcar_drif: fix potential uninitialized variable use

PATCH In review Arnd Bergmann 2 participants 2 messages Sep 14, 2017 – Sep 15, 2017

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

PATCH 1/1 rcar_drif: fix potential uninitialized variable use

Older compilers like gcc-4.6 may run into a case that returns an uninitialized variable from rcar_drif_enable_rx() if that function was ever called with an empty cur_ch_mask:

drivers/media/platform/rcar_drif.c:658:2: error: ‘ret’ may be used uninitialized in this function [-Werror=uninitialized]

Newer compilers don't have that problem as they optimize the 'ret' variable away and just return zero in that case.

This changes the function to return -EINVAL for this particular failure, to make it consistent across all compiler versions. In case gcc gets changed to report a warning for it in the future, it's also a good idea to shut it up now.

---
 drivers/media/platform/rcar_drif.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/rcar_drif.c +1 -1
index 522364ff0d5d..2c6afd38b78a 100644
@@ -630,7 +630,7 @@ static int rcar_drif_enable_rx(struct rcar_drif_sdr *sdr)
 {
 	unsigned int i;
 	u32 ctr;
-	int ret;
+	int ret = -EINVAL;
 
 	/*
 	 * When both internal channels are enabled, they can be synchronized
Signature · 1 line
2.9.0
Acked-by on v1 1/1
#1 lore raw

Hi Arnd,

Thank you for the patch.

Quoted 13 lines

Subject: [PATCH] [media] rcar_drif: fix potential uninitialized variable use

Older compilers like gcc-4.6 may run into a case that returns an uninitialized variable from rcar_drif_enable_rx() if that function was ever called with an empty cur_ch_mask:

drivers/media/platform/rcar_drif.c:658:2: error: ‘ret’ may be used uninitialized in this function [-Werror=uninitialized]

Newer compilers don't have that problem as they optimize the 'ret' variable away and just return zero in that case.

Quoted 7 lines

This changes the function to return -EINVAL for this particular failure, to make it consistent across all compiler versions.
In case gcc gets changed to report a warning for it in the future, it's also a good idea to shut it up now.

Thanks,
Ramesh