[PATCH] media: cx23885: check allocation return

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Checking of kmalloc() seems to have been committed - as
cx23885_dvb_register() is checking for != 0 return, returning
-ENOMEM should be fine here.  While at it address the coccicheck
suggestion to move to kmemdup rather than using kmalloc+memcpy.

Signed-off-by: Nicholas Mc Guire <hofrat@xxxxxxxxx>
Fixes: 46b21bbaa8a8 ("[media] Add support for DViCO FusionHDTV DVB-T Dual Express2")
---
Problem located with an experimental coccinelle script

Patch was compile tested with: x86_64_defconfig + MEDIA_SUPPORT=y
MEDIA_PCI_SUPPORT=y, MEDIA_DIGITAL_TV_SUPPORT=y,
MEDIA_ANALOG_TV_SUPPORT=y (for VIDEO_DEV), RC_CORE=y
VIDEO_CX23885=y

The coccicheck on the initial fix for kmalloc only reported:
drivers/media/pci/cx23885//cx23885-dvb.c:1477:33-40: WARNING opportunity for kmemdup
so that was merged into this patch - the return value still needs to
be checked.

Patch is against 5.0-rc2 (localversion-next is next-20190118)

 drivers/media/pci/cx23885/cx23885-dvb.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c b/drivers/media/pci/cx23885/cx23885-dvb.c
index 0d0929c..225cdfe 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -1474,8 +1474,11 @@ static int dvb_register(struct cx23885_tsport *port)
 		if (fe0->dvb.frontend != NULL) {
 			struct i2c_adapter *tun_i2c;
 
-			fe0->dvb.frontend->sec_priv = kmalloc(sizeof(dib7000p_ops), GFP_KERNEL);
-			memcpy(fe0->dvb.frontend->sec_priv, &dib7000p_ops, sizeof(dib7000p_ops));
+			fe0->dvb.frontend->sec_priv = kmemdup(&dib7000p_ops,
+							sizeof(dib7000p_ops),
+							GFP_KERNEL);
+			if (!fe0->dvb.frontend->sec_priv)
+				return -ENOMEM;
 			tun_i2c = dib7000p_ops.get_i2c_master(fe0->dvb.frontend, DIBX000_I2C_INTERFACE_TUNER, 1);
 			if (!dvb_attach(dib0070_attach, fe0->dvb.frontend, tun_i2c, &dib7070p_dib0070_config))
 				return -ENODEV;
-- 
2.1.4




[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux