media: cx18: Access v4l2_fh from file
Hello Jacopo Mondi,
Commit 7b9eb53e8591 ("media: cx18: Access v4l2_fh from file") from Aug 10, 2025 (linux-next), leads to the following Smatch static checker warning:
drivers/media/pci/cx18/cx18-driver.c:1223 cx18_init_on_first_open() error: NULL dereference inside function drivers/media/pci/cx18/cx18-driver.c:1229 cx18_init_on_first_open() error: NULL dereference inside function drivers/media/pci/cx18/cx18-driver.c:1230 cx18_init_on_first_open() error: NULL dereference inside function drivers/media/pci/ivtv/ivtv-driver.c:1313 ivtv_init_on_first_open() error: NULL dereference inside function drivers/media/pci/ivtv/ivtv-driver.c:1319 ivtv_init_on_first_open() error: NULL dereference inside function
drivers/media/pci/cx18/cx18-driver.c
1214 /* Set initial frequency. For PAL/SECAM broadcasts no
1215 'default' channel exists AFAIK. */
1216 if (cx->std == V4L2_STD_NTSC_M_JP)
1217 vf.frequency = 1460; /* ch. 1 91250*16/1000 */
1218 else if (cx->std & V4L2_STD_NTSC_M)
1219 vf.frequency = 1076; /* ch. 4 67250*16/1000 */
1220
1221 video_input = cx->active_input;
1222 cx->active_input++; /* Force update of input */
--> 1223 cx18_s_input(NULL, &fh, video_input);
^^^^The patch adds a new dereference of "file" but some of the callers pass a NULL pointer.
1224
1225 /* Let the VIDIOC_S_STD ioctl do all the work, keeps the code
1226 in one place. */
1227 cx->std++; /* Force full standard initialization */
1228 std = (cx->tuner_std == V4L2_STD_ALL) ? V4L2_STD_NTSC_M : cx->tuner_std;
1229 cx18_s_std(NULL, &fh, std);
1230 cx18_s_frequency(NULL, &fh, &vf);
1231 return 0;
1232 }regards,
dan carpenter
Hi Dan
Quoted 24 lines · Dan Carpenter
Hello Jacopo Mondi,
Commit
7b9eb53e8591("media: cx18: Accessv4l2_fhfrom file") from Aug 10, 2025 (linux-next), leads to the following Smatch static checker warning:
drivers/media/pci/cx18/cx18-driver.c:1223cx18_init_on_first_open()error: NULL dereference inside functiondrivers/media/pci/cx18/cx18-driver.c:1229cx18_init_on_first_open()error: NULL dereference inside functiondrivers/media/pci/cx18/cx18-driver.c:1230cx18_init_on_first_open()error: NULL dereference inside functiondrivers/media/pci/ivtv/ivtv-driver.c:1313ivtv_init_on_first_open()error: NULL dereference inside functiondrivers/media/pci/ivtv/ivtv-driver.c:1319ivtv_init_on_first_open()error: NULL dereference inside function
drivers/media/pci/cx18/cx18-driver.c1214 /* Set initial frequency. For PAL/SECAM broadcasts no 1215 'default' channel exists AFAIK. */ 1216 if (cx->std == V4L2_STD_NTSC_M_JP) 1217 vf.frequency = 1460; /* ch. 1 91250*16/1000 */ 1218 else if (cx->std & V4L2_STD_NTSC_M) 1219 vf.frequency = 1076; /* ch. 4 67250*16/1000 */ 1220 1221 video_input = cx->active_input; 1222 cx->active_input++; /* Force update of input */ --> 1223 cx18_s_input(NULL, &fh, video_input); ^^^^
Quoted 2 lines
The patch adds a new dereference of "file" but some of the callers pass a NULL pointer.
smart smatch! Indeed the DVB layer calls the ioctl operation handler directly, without a valid file *.
Quoted 8 lines
1224
1225 /* Let the VIDIOC_S_STD ioctl do all the work, keeps the code
1226 in one place. */
1227 cx->std++; /* Force full standard initialization */
1228 std = (cx->tuner_std == V4L2_STD_ALL) ? V4L2_STD_NTSC_M : cx->tuner_std;
1229 cx18_s_std(NULL, &fh, std);
1230 cx18_s_frequency(NULL, &fh, &vf);And I guess the same reasoning applies to these two.
I'll send a patch right away
Quoted 5 lines
1231 return 0; 1232 }regards,
dan carpenter
Quoted 42 lines · Jacopo Mondi
Hi Dan
Quoted 24 lines · Dan Carpenter
Hello Jacopo Mondi,
Commit
7b9eb53e8591("media: cx18: Accessv4l2_fhfrom file") from Aug 10, 2025 (linux-next), leads to the following Smatch static checker warning:
drivers/media/pci/cx18/cx18-driver.c:1223cx18_init_on_first_open()error: NULL dereference inside functiondrivers/media/pci/cx18/cx18-driver.c:1229cx18_init_on_first_open()error: NULL dereference inside functiondrivers/media/pci/cx18/cx18-driver.c:1230cx18_init_on_first_open()error: NULL dereference inside functiondrivers/media/pci/ivtv/ivtv-driver.c:1313ivtv_init_on_first_open()error: NULL dereference inside functiondrivers/media/pci/ivtv/ivtv-driver.c:1319ivtv_init_on_first_open()error: NULL dereference inside function
drivers/media/pci/cx18/cx18-driver.c1214 /* Set initial frequency. For PAL/SECAM broadcasts no 1215 'default' channel exists AFAIK. */ 1216 if (cx->std == V4L2_STD_NTSC_M_JP) 1217 vf.frequency = 1460; /* ch. 1 91250*16/1000 */ 1218 else if (cx->std & V4L2_STD_NTSC_M) 1219 vf.frequency = 1076; /* ch. 4 67250*16/1000 */ 1220 1221 video_input = cx->active_input; 1222 cx->active_input++; /* Force update of input */ --> 1223 cx18_s_input(NULL, &fh, video_input); ^^^^Quoted 2 lines
The patch adds a new dereference of "file" but some of the callers pass a NULL pointer.
smart smatch! Indeed the DVB layer calls the ioctl operation handler directly, without a valid file *.
Quoted 8 lines
1224 1225 /* Let the VIDIOC_S_STD ioctl do all the work, keeps the code 1226 in one place. */ 1227 cx->std++; /* Force full standard initialization */ 1228 std = (cx->tuner_std == V4L2_STD_ALL) ? V4L2_STD_NTSC_M : cx->tuner_std; 1229 cx18_s_std(NULL, &fh, std); 1230 cx18_s_frequency(NULL, &fh, &vf);
Quoted 1 line
And I guess the same reasoning applies to these two.
ivtv does the same (cx18 is closely based on ivtv).
Regards,
Hans
Quoted 9 lines
I'll send a patch right away
Quoted 5 lines
1231 return 0; 1232 }regards,
dan carpenter
Hi Hans,
Quoted 43 lines · Hans Verkuil
Quoted 42 lines · Jacopo Mondi
Hi Dan
Quoted 24 lines · Dan Carpenter
Hello Jacopo Mondi,
Commit
7b9eb53e8591("media: cx18: Accessv4l2_fhfrom file") from Aug 10, 2025 (linux-next), leads to the following Smatch static checker warning:
drivers/media/pci/cx18/cx18-driver.c:1223cx18_init_on_first_open()error: NULL dereference inside functiondrivers/media/pci/cx18/cx18-driver.c:1229cx18_init_on_first_open()error: NULL dereference inside functiondrivers/media/pci/cx18/cx18-driver.c:1230cx18_init_on_first_open()error: NULL dereference inside functiondrivers/media/pci/ivtv/ivtv-driver.c:1313ivtv_init_on_first_open()error: NULL dereference inside functiondrivers/media/pci/ivtv/ivtv-driver.c:1319ivtv_init_on_first_open()error: NULL dereference inside function
drivers/media/pci/cx18/cx18-driver.c1214 /* Set initial frequency. For PAL/SECAM broadcasts no 1215 'default' channel exists AFAIK. */ 1216 if (cx->std == V4L2_STD_NTSC_M_JP) 1217 vf.frequency = 1460; /* ch. 1 91250*16/1000 */ 1218 else if (cx->std & V4L2_STD_NTSC_M) 1219 vf.frequency = 1076; /* ch. 4 67250*16/1000 */ 1220 1221 video_input = cx->active_input; 1222 cx->active_input++; /* Force update of input */ --> 1223 cx18_s_input(NULL, &fh, video_input); ^^^^Quoted 2 lines
The patch adds a new dereference of "file" but some of the callers pass a NULL pointer.
smart smatch! Indeed the DVB layer calls the ioctl operation handler directly, without a valid file *.
Quoted 8 lines
1224 1225 /* Let the VIDIOC_S_STD ioctl do all the work, keeps the code 1226 in one place. */ 1227 cx->std++; /* Force full standard initialization */ 1228 std = (cx->tuner_std == V4L2_STD_ALL) ? V4L2_STD_NTSC_M : cx->tuner_std; 1229 cx18_s_std(NULL, &fh, std); 1230 cx18_s_frequency(NULL, &fh, &vf);
Quoted 3 lines
Quoted 1 line
And I guess the same reasoning applies to these two.
ivtv does the same (cx18 is closely based on ivtv).
Thanks, I'll address both in a single series
Quoted 15 lines
Regards,
Hans
Quoted 9 lines
I'll send a patch right away
Quoted 5 lines
1231 return 0; 1232 }regards,
dan carpenter