summaryrefslogtreecommitdiff
path: root/drivers/media
AgeCommit message (Collapse)Author
11 daysmedia: microchip-isc: fix ISC_PFG_CFG0_BPS macro name typoBalakrishnan Sambath
The BPS field macros for ISC_PFE_CFG0 were spelled ISC_PFG_CFG0_BPS_* (NINE, TEN, ELEVEN, TWELVE). The register is PFE, not PFG. Rename them to ISC_PFE_CFG0_BPS_* to match the register and the EIGHT and MASK macros. No functional change. Signed-off-by: Balakrishnan Sambath <balakrishnan.s@microchip.com> Reviewed-by: Eugen Hristev <ehristev@kernel.org> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: microchip-isc: store the unshifted PFE_CFG0 BPS valueBalakrishnan Sambath
pfe_cfg0_bps held a pre-shifted BPS value (ISC_PFE_CFG0_BPS_EIGHT was 0x4 << 28) ORed straight into the register. The other format selectors like cfa_baycfg store the bare field value and position it at the write, so this one was inconsistent. Store the bare BPS value and apply it with FIELD_PREP() at the PFE_CFG0 write, and fix the pfe_cfg0_bps comment to match. No functional change. Suggested-by: Eugen Hristev <ehristev@kernel.org> Signed-off-by: Balakrishnan Sambath <balakrishnan.s@microchip.com> Reviewed-by: Eugen Hristev <ehristev@kernel.org> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: microchip-isc: do not touch WB registers when not streamingBalakrishnan Sambath
isc_s_awb_ctrl() called isc_update_awb_ctrls() unconditionally, writing the white balance registers even when the device is runtime suspended; on many ARM platforms accessing the unclocked registers is an external abort. The write was also done without awb_lock, racing isc_awb_work(), which holds it so the DMA done IRQ cannot latch a half-updated pipeline. Write the registers only while streaming and not stopping, under awb_lock, and update the profile there. The isc->stop check covers the window where isc_stop_streaming() has gated the clocks but vb2 still reports streaming. Otherwise the new values stay cached and isc_configure() programs them at the next stream start. Fixes: 4e52889f48fe ("media: atmel: atmel-isc-base: expose white balance as v4l2 controls") Cc: stable@vger.kernel.org Reviewed-by: Eugen Hristev <ehristev@kernel.org> Signed-off-by: Balakrishnan Sambath <balakrishnan.s@microchip.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: microchip-isc: disable histogram and flush AWB work on teardownBalakrishnan Sambath
isc_stop_streaming() and the isc_start_streaming() error path dropped the runtime PM reference with the histogram still enabled. A HISDONE firing just before the stop, or a failed isc_update_profile() on the start path, can queue isc_awb_work(), which reads the histogram registers before taking its own PM reference and faults on the unclocked device. Disable the histogram, synchronize the IRQ and flush the work before the device is left unclocked. isc_configure() is the one enabling the histogram and then calling isc_update_profile(), so do the cleanup in its own failure path; isc_stop_streaming() does the same on teardown. synchronize_irq() must come before cancel_work_sync(), so an in-flight handler cannot re-queue awb_work after it is cancelled. Fixes: 93d4a26c3dab ("[media] atmel-isc: add the isc pipeline function") Cc: stable@vger.kernel.org Signed-off-by: Balakrishnan Sambath <balakrishnan.s@microchip.com> Reviewed-by: Eugen Hristev <ehristev@kernel.org> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: microchip-isc: synchronize the IRQ before disabling clocks on stopBalakrishnan Sambath
isc_stop_streaming() masks the DMA interrupt and then drops the runtime PM reference, which disables the ISC clocks. microchip_isc_interrupt() may still be executing on another CPU at that point; it reads ISC_INTSR over regmap, and touching the unclocked registers triggers an external abort. Store the IRQ number at probe and call synchronize_irq() after masking the interrupt, before dropping the PM reference. Fixes: 106267444f12 ("[media] atmel-isc: add the Image Sensor Controller code") Cc: stable@vger.kernel.org Signed-off-by: Balakrishnan Sambath <balakrishnan.s@microchip.com> Reviewed-by: Eugen Hristev <ehristev@kernel.org> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: microchip-isc: take a reference on the parsed endpointsBalakrishnan Sambath
for_each_endpoint_of_node() drops the reference on the current node as it advances. xisc_parse_dt() and isc_parse_dt() store the node in subdev_entity->epn and release it later with of_node_put(), but never took their own reference, so the stored pointer refers to an already-released node. This underflows the refcount and can use-after-free, reachable through the camera device tree overlay. Take a reference with of_node_get() when storing the node, and drop it in microchip_isc_subdev_cleanup() so the entities the bind loop never reaches on an early exit do not leak it. Fixes: c9aa973884a1 ("media: atmel: atmel-isc: add microchip-xisc driver") Fixes: d6701f13bd07 ("media: atmel: Use v4l2_async_notifier_add_fwnode_remote_subdev") Cc: stable@vger.kernel.org Signed-off-by: Balakrishnan Sambath <balakrishnan.s@microchip.com> Reviewed-by: Eugen Hristev <ehristev@kernel.org> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: microchip-isc: fix awb_mutex and lock lifecycleBalakrishnan Sambath
isc->lock and awb_mutex were initialised in isc_async_complete() and destroyed in isc_async_unbind(), tying their lifetime to the subdev bind/unbind cycle instead of the device: - isc_async_unbind() destroyed awb_mutex before cancel_work_sync(), which takes it; - a failed .complete() left them initialised, and isc->lock was destroyed only on the .complete() error path, so the normal unbind path leaked it; - a rebind runs .complete() again and reinitialises a live mutex. Initialise both with devm_mutex_init() at probe so they live for the whole device lifetime and are freed at remove, and drop the init and destroy from the .complete()/.unbind() callbacks. isc_async_complete_err then only returned ret, so drop the label and return directly at each error site. Fixes: 314c96e5203d ("media: atmel: atmel-isc-base: use mutex to lock awb workq from streaming") Cc: stable@vger.kernel.org Reviewed-by: Eugen Hristev <ehristev@kernel.org> Signed-off-by: Balakrishnan Sambath <balakrishnan.s@microchip.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: stm32: dcmipp: instantiate & link stm32mp25 subdevsAlain Volmat
Add topology of the two pixel pipes (main & aux) of the stm32mp25. Do not make the link from dcmipp_input immutable and enabled by default since not all pipes are always used together so when a pipeline is not being used its link should be disconnected to allow proper pipeline check. Not doing this would most probably lead to pipeline start failure due to incompatible pads configurations on the unused pipe. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: stm32: dcmipp: rename bytecap into captureAlain Volmat
Since the bytecap video driver is now handling all capture (byte & pixel), rename the file and structs *into capture. This is done by: - renaming of dcmipp-bytecap.c into dcmipp-capture.c - replace of dcmipp_bytecap strings into dcmipp_capture Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: stm32: dcmipp: add pixel-pipe support in bytecapAlain Volmat
The dump pipe and pixel pipes capture part (tail of each pipe) is different in that pixel pipes have a pixel packer capable of generating various output format while the on dump pipe no such manipulation is possible. Still, all the buffer handling, format related manipulations are all same hence both dump and pixel pipe capture part are put together to avoid having large duplication of code. This patch adds the pixel pipe capture within bytecap hence name isn't modified and a further commit should rename the file and probably function name to not only highlight byte capture (aka dump pipe). Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: stm32: dcmipp: pixelproc: addition of dcmipp-pixelproc subdevAlain Volmat
Addition of the driver for dcmipp-pixelproc subdev. This subdev is the last one before the capture device at the tail of both main and aux pipelines. It is in charge of: - framerate adjustment - downscale - gamma correction - color conversion - pixel packing Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: stm32: dcmipp: addition of a dcmipp-isp subdevAlain Volmat
The ISP subdev is the first element after input of the main pipeline. Part (static configuration) of this block is done via this subdev while other configuration done on a per-frame basis will be done via a output metadata device attached to this subdev. This subdev handled the following features of the ISP block: - statistic removal (top / bottom of the frame) - decimation - demosaicing - control of frame export to the aux pipeline Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: stm32: dcmipp: add pixel pipes helper functionsAlain Volmat
Pixel pipes are made of an isp subdev (only main pipe) and a postproc subdev. This commit add a helper functions common to those 2 subdevs such as for handling format enumeration, set_selection handling, so that they do not have to be duplicated in the two subdeves. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: stm32: dcmipp: introduce a dcmipp global media_pipelineAlain Volmat
With the introduction of stm32mp25 containing several capture devices, it becomes necessary to share the media_pipeline structure among all capture devices since subdev pads can be shared between several capture devices. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: stm32: dcmipp: configure csi input of all pipes on stm32mp25Alain Volmat
The STM32MP25 has CSI input and 2 additional pixel pipes in addition to the byte pipe. Each pipe can select which data to receive based on CSI VC/DT selection. The multi-stream support of DCMIPP will be added in a future commit, however, to start putting proper control method, the input subset has now 3 SRC pads, one per pipe available. Currently, and until multi-stream support is added, same data is sent to all pipes. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: stm32: dcmipp: correct swap in YUYV data with parallel inputAlain Volmat
When used with parallel input, the DCMIPP is expecting data to come in YUYV order (for all DUMP/MAIN and AUX pipes). Not doing so will lead to bad color generated by the pipes when processing is done. The DUMP pipe is also doing by default a swap since, while it accepts YUYV data, it will by default generate UYVY data. Current implementation is not correct for parallel input since it is performing a cycle swap on the input side and since the dump pipe is also internally doing a swap, the data captured from the dump pipe are correct, while the data captured from the main / aux pipes are not. To correct this, only perform cycle swap when it is necessary, hence changing from YUYV to UYVY for example, and for all parallel YUV MBUS, add the P0PPCR based SWAPYUV to put back the data into the ordering of the input. Keep previous behavior when the SWAPYUV is not available (such as stm32mp13). Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: stm32: dcmipp: move common structures in dcmipp-common.hAlain Volmat
Move the structure dcmipp_pipeline_config into dcmipp-common.h so that all subdeves can have access to the information of capabilities. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: stm32: dcmipp: bytecap: protect CMIER register accessAlain Volmat
CMIER register is common between all pipes and thus needs to be protected from concurrent access. The struct v4l2_device structure, unique to the whole driver embeds a spin_lock which can also be used by the driver itself as explained in its description. Rely on this spin_lock to protect from concurrent access to the CMIER register. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: stm32: dcmipp: make dcmipp_state & cmsr2 read commonAlain Volmat
In preparation of the introduction of the pixel pipes capture devices, move struct dcmipp_state into common header and perform interrupt status register CMSR2 into the core interrupt handler and share the value with each subdevs. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: stm32: dcmipp: share struct dcmipp_device among subdevsAlain Volmat
In preparation of need for sharing of data between subdevices, make the struct dcmipp_device structure part of dcmipp_common.h and share it with subdevs at init time. This allows for simplifying parameters of each subdev init function as well. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
11 daysmedia: i2c: add Himax HM1246 image sensor driverMatthias Fend
Add a V4L2 sub-device driver for Himax HM1246 image sensor. The Himax HM1246-AWD is a 1/3.7-Inch CMOS image sensor SoC with an active array size of 1296 x 976. It is programmable through an I2C interface and connected via parallel bus. The sensor has an internal ISP with a complete image processing pipeline including control loops. However, this driver uses the sensor in raw mode and the entire ISP is bypassed. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Matthias Fend <matthias.fend@emfend.at> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
11 daysmedia: i2c: add os02g10 image sensor driverElgin Perumbilly
Add a v4l2 subdevice driver for the Omnivision os02g10 sensor. The Omnivision os02g10 is a CMOS image sensor with an active array size of 1920 x 1080. The following features are supported: - Manual exposure an gain control support - vblank/hblank control support - vflip/hflip control support - Test pattern control support - Supported resolution: 1920 x 1080 @ 30fps (SBGGR10) Signed-off-by: Elgin Perumbilly <elgin.perumbilly@siliconsignals.io> Reviewed-by: Tarang Raval <tarang.raval@siliconsignals.io> Reviewed-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
11 daysmedia: usb: em28xx: check if vbi is supported before calling vb2_queue_initHans Verkuil
If the device does not support vbi, then the vbi queue is still initialized with vb2_queue_init(), which fails with a WARNing because the q->lock pointer is never set. Only call vb2_queue_init for the vbi queue if vbi is actually supported. Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org> Tested-by: Hans Verkuil <hverkuil+cisco@kernel.org> Reported-by: Lars Ljung <lars@matholka.se> Closes: https://lore.kernel.org/linux-media/8ede91cc-b505-458a-94ef-fb02270f9701@matholka.se/T/#u Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>
12 daysmedia: m2m-deinterlace: fix default capture fieldXu Rao
queue_init() initializes default formats for both the source and capture queues. It first sets the source field to V4L2_FIELD_SEQ_TB, but then stores the capture default, V4L2_FIELD_INTERLACED_TB, in the source queue again while initializing the capture queue. This overwrites the valid source default and leaves the capture field at its zero-initialized value, V4L2_FIELD_ANY. vidioc_streamon() accepts only V4L2_FIELD_SEQ_TB or V4L2_FIELD_SEQ_BT on the source queue, and requires the capture queue to use a compatible interlaced or NONE field. Userspace that relies on the default formats can therefore get -EINVAL when starting streaming. Initialize the capture field instead. The bug is usually hidden because mem2mem applications commonly call S_FMT on both queues before streaming; the TRY_FMT paths normalize the fields and S_FMT overwrites q_data[].field. Fixes: 8f0755c06b90 ("[media] media: Add mem2mem deinterlacing driver") Cc: stable@vger.kernel.org Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Signed-off-by: Xu Rao <raoxu@uniontech.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: marvell: mcam: stop DMA and cancel s_bh_work before freeing DMA buffersFan Wu
In vmalloc mode the frame-completion IRQ queues mcam_frame_work() on cam->s_bh_work, which memcpy()s from the dma_bufs[] that mcam_free_dma_bufs() frees with dma_free_coherent(). mccic_shutdown() frees those buffers without stopping the controller, so while streaming a late frame IRQ can re-arm the work after the buffers are gone, causing a use-after-free. Stop the controller in mccic_shutdown() when streaming is still active (gated on an open fd, which holds a runtime-PM reference, so the device is powered), cancel s_bh_work in mcam_free_dma_bufs(), and move INIT_WORK() into mccic_register() before the device can be published. Fixes: 67a8dbbc4e04 ("[media] marvell-cam: Basic working MMP camera driver") Cc: stable@vger.kernel.org Signed-off-by: Fan Wu <fanwu01@zju.edu.cn> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: marvell: cafe: drop unneeded semicolonJulia Lawall
When a function-like macro expands to an expression, that expression doesn't need a semicolon after it. All uses have been verified to have their own semicolons. This was found using the following Coccinelle semantic patch: @r@ identifier i : script:ocaml() { String.lowercase_ascii i = i }; expression e; @@ *#define i(...) e; Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: marvell-cam: fix unmet dependency for VIDEO_MMP_CAMERAJulian Braha
VIDEO_MMP_CAMERA selects I2C_GPIO without ensuring 'GPIOLIB || COMPILE_TEST' is enabled, despite I2C_GPIO depending on it. Let's add the same dependency to VIDEO_MMP_CAMERA. This unmet dependency bug was found by kconfirm, a static analysis tool for Kconfig. Fixes: 67a8dbbc4e04 ("[media] marvell-cam: Basic working MMP camera driver") Cc: stable@vger.kernel.org Signed-off-by: Julian Braha <julianbraha@gmail.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: vidtv: validate the frequency module parametersAlberto Pimpo
The lists of frequencies the simulated tuner locks onto are module parameters, and were handed over to the tuner module without being checked first. A terrestrial or cable frequency outside the range the demodulator reports to the DVB core is unreachable, as dvb_frontend_check_parameters() rejects such a tuning request before the tuner is ever asked about the frequency. A satellite frequency outside the Ku-band covered by the simulated LNBf is equally meaningless, since it is downconverted using the LNBf local oscillators before reaching the tuner. In both cases vidtv used to initialize successfully and then never lock on anything, leaving no clue about the cause. Check the terrestrial and cable frequencies against the range advertised by the demodulator, and the satellite ones against the Ku-band covered by the simulated LNBf, failing the probe with an explicit error message otherwise. Signed-off-by: Alberto Pimpo <me@albertopimpo.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: vidtv: fix uaf in vidtv_bridge_on_new_pkts_availJeffin Philip
Attempting to unbind a dvbdevice that is in the process of feeding data causes a UAF as we free the underlying device without stopping the feed first. Fix this by stopping the stream first using vidtv_stop_streaming(). However, our codepath in the reproducer (mentioned in the below reply) does not decrement our users (dmxdev->dvr_dvbdev->users) to 1 after it has been incremented to 2 by our read() in the reproducer, that is only possible on .release. This can cause a task hang as dvb_dmxdev_release() uses wait_event() in the wait_queue unless we use a close(fd)(in the reproducer). Is this a problem? Please advise. Reported-by: syzbot+c7fc4794e59786f5b4dc@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=c7fc4794e59786f5b4dc Fixes: f90cf6079bf6 ("media: vidtv: add a bridge driver") Cc: stable@vger.kernel.org Signed-off-by: Jeffin Philip <jeffinphilip14@gmail.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: vidtv: fix frontend reference leak on unbindPiyush Patle
dvb_register_frontend() keeps two references to the frontend. One is released by dvb_unregister_frontend(), and the other by dvb_frontend_detach(). vidtv only called dvb_unregister_frontend(), so the second reference was never released. As a result, __dvb_frontend_free() was never called, leaking the frontend private data and its struct dvb_device. The detach call was removed by commit 63101b756893 ("media: vidtv: fix driver unbind/remove") because it caused an OOPS. The demod .release callback freed vidtv_demod_state, and the I2C remove callbacks then accessed the freed state. That commit also removed those accesses from the I2C remove callbacks. Restore the detach call, but remove the demod .release callback. vidtv_demod_state is owned by the I2C client and is already freed by vidtv_demod_i2c_remove(), so the frontend detach path should not free it. Tested with kmemleak and KASAN over 10 bind/unbind cycles. The reported frontend and dvb_device leaks were present before the fix and were gone after it, with no KASAN reports. Reported-by: syzbot+32f018fd65e799f79ae0@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=32f018fd65e799f79ae0 Fixes: 63101b756893 ("media: vidtv: fix driver unbind/remove") Cc: stable@vger.kernel.org Tested-by: syzbot+32f018fd65e799f79ae0@syzkaller.appspotmail.com Signed-off-by: Piyush Patle <piyushpatle228@gmail.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: vicodec: make encoder CAPTURE dimensions read-onlyJunrui Luo
Setting the encoder's compressed CAPTURE format to a smaller resolution than the raw OUTPUT format makes the encoder write past the end of the CAPTURE buffer. For a stateful encoder the CAPTURE width and height are not client-settable; Documentation/userspace-api/media/v4l/dev-encoder.rst specifies them as "ignored (read-only)" on VIDIOC_S_FMT. vicodec only implements half of that: vidioc_s_fmt_vid_out() derives the CAPTURE coded size and sizeimage from the OUTPUT format, but S_FMT on the CAPTURE queue overwrites them. The encoder then takes its geometry from the OUTPUT queue alone, and v4l2_fwht_encode() gets no destination length. Overwrite the requested width and height with the OUTPUT queue's coded dimensions in vidioc_try_fmt_vid_cap(), making them read-only as the interface requires. Fixes: efec9c815e5d ("media: vicodec: pass on enc output format to capture side") Reported-by: Yuhao Jiang <danisjiang@gmail.com> Assisted-by: Claude:claude-opus-5 Cc: stable@vger.kernel.org Signed-off-by: Junrui Luo <moonafterrain@outlook.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: vicodec: fix out-of-bounds write on under-rounded coded dimensionsJunrui Luo
A capture format whose width or height is one more than a multiple of 16 makes the FWHT codec write one 8x8 block row, or column, past the end of the capture plane, and read the same block out of the reference frame for P-coded frames. vic_round_dim() is documented to round a frame dimension up so that both the luma and the chroma plane end up a multiple of 8, but it only rounds the chroma plane: round_up((dim) / (div), 8) * (div) For div == 2 the result is a multiple of 16 in every case but one: when dim % 16 == 1, dim / div is already a multiple of 8 and the macro returns dim - 1. encode_plane() and decode_plane() round the same dimension with round_up(dim, 8), which yields dim + 7 -- one block more than the coded dimension that sized the buffer. On a KASAN-enabled kernel, a 641x360 YUYV P-frame triggers: BUG: KASAN: slab-out-of-bounds in add_deltas+0x450/0xcc0 Read of size 1 at addr ffff888009070800 by task trigger_bin/70 Call Trace: add_deltas+0x450/0xcc0 decode_plane+0x1916/0x3390 fwht_decode_frame+0x173/0x620 v4l2_fwht_decode+0x751/0x1120 device_run+0x6bb/0x1850 Round the dimension itself up to a multiple of 8 * div. The rounding changes only for div == 2 and dim % 16 == 1, and MAX_WIDTH and MAX_HEIGHT are both multiples of 16, so the rounded value still fits the advertised limits. Fixes: 3b15f68e19c2 ("media: vicodec: Add support for resolution change event.") Reported-by: Yuhao Jiang <danisjiang@gmail.com> Assisted-by: Claude:claude-opus-5 Cc: stable@vger.kernel.org Signed-off-by: Junrui Luo <moonafterrain@outlook.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: vimc: sensor: fix pixel_rate type to resolve do_div() warningFaizel K B
vsensor->pixel_rate->val is a plain s32 field. Declaring the local "pixel_rate" variable as u64 misrepresented its actual range and made do_div()'s divisor look wider than the 32-bit division it actually performs, which is exactly what the do_div() coccinelle check warns. Revert pixel_rate back to its original s32 type to match vsensor->pixel_rate->val, resolving the warning correctly. Fixes: ec1e620b2454 ("media: vimc: sensor: Add pixel_rate,vblank and hblank configuration") Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202604191731.10nxGZ92-lkp@intel.com/ Link: https://lore.kernel.org/lkml/CANiDSCs9s03DUjKwcPgDtZt2QJ4i0FGwab4zpEP+wCawagSC2Q@mail.gmail.com/ Cc: stable@vger.kernel.org Signed-off-by: Faizel K B <faizel.kb@gmail.com> Reviewed-by: Ricardo Ribalda <ribalda@chromium.org> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: tda18250: Use %*ph to print small bufferAndy Shevchenko
Use %*ph format to print small buffer as hex string. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: vim2m: keep transaction buffer count stable while streamingYounho Choi
V4L2_CID_TRANS_NUM_BUFS controls how many buffer pairs a vim2m mem2mem job processes before the job is completed. The driver stores the value in ctx->translen and device_work() uses it later to decide whether the current transaction should continue. Letting userspace change this control while streaming is active can make a queued job observe a different transaction length than the one it started with. That leaves the transaction state inconsistent with the buffers currently queued for the job. Grab the transaction buffer count control while either queue is streaming, and release it only after both queues have stopped streaming. The V4L2 control framework then rejects changes with -EBUSY while the value is in use, while still allowing userspace to configure the value before streaming starts. Keep the control handler alive until after v4l2_m2m_ctx_release(), since releasing the mem2mem context can call stop_streaming(), which now ungrabs the control. Fixes: 96d8eab5d0a1 ("V4L/DVB: [v5,2/2] v4l: Add a mem-to-mem videobuf framework test device") Cc: stable@vger.kernel.org Signed-off-by: Younho Choi <gdool88@mju.ac.kr> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: saa7146: Initialize interrupt lock before requesting IRQRunyu Xiao
The saa7146 interrupt handler can call SAA7146_IER_DISABLE(), which serializes register access with dev->int_slock. request_irq() allows the shared handler to run before saa7146_init_one() reaches the current lock initialization block. Initialize dev->int_slock before requesting the interrupt so every handler path sees an initialized lock. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Assisted-by: Codex:GPT-5 Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: go7007: bound EZ-USB I2C transfers to the usb_buf sizeShengzhuo Wei
go7007_usb_i2c_master_xfer() copies msgs[i].len bytes into go->usb_buf, a 16-byte buffer embedded in struct go7007, without any length check. The adapter declares no transfer limits, so an SMBus block transfer issued through /dev/i2c-N can write up to 34 bytes into it and corrupt the struct fields that follow the buffer. Bound the transfer size with i2c_adapter_quirks so the I2C core rejects oversized messages before they reach the driver. Fixes: 7955f03d18d1 ("[media] go7007: move out of staging into drivers/media/usb.") Cc: stable@vger.kernel.org Signed-off-by: Shengzhuo Wei <me@cherr.cc> Assisted-by: GLM:5.3 Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: radio: si4713: replace msleep() with usleep_range() for delays less ↵Bhoomika Hardwani
than 20ms msleep() isn't precise for delays under 20ms and relies on jiffies, which can lead to sleeps longer than requested, depending on the system's HZ configurations. Replace msleep(3) with usleep_range(3000, 4000) to use high-resolution timers, without forcing the system to wait unnecessarily. Signed-off-by: Bhoomika Hardwani <bhoomika.hardwani@gmail.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: em28xx: Fix PAL analog TV coloursBradford Love
Red/Blue chroma are swapped on PAL analog TV due to register 0x7A07 missing in the configuration block for PAL. Copying in the setting for composite fixes the issue and everything decodes properly. Signed-off-by: Bradford Love <brad@nextdimension.cc> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: i2c: tc358743: add missing color-space stringsLinkai Gong
VI_STATUS3 S_V_COLOR is four bits, so the index after the shift is 0-15. input_color_space[] only has 14 entries. Add the two reserved values so log_status() cannot walk off the table. Fixes: d32d98642de6 ("[media] Driver for Toshiba TC358743 HDMI to CSI-2 bridge") Cc: stable@vger.kernel.org Signed-off-by: Linkai Gong <gonglinkai@kylinos.cn> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: saa7164: remove register dump debugging helperZain Aboobacker
saa7164_dumpregs() dumps device register contents during initialization for debugging purposes. The helper has a single caller and is explicitly marked for removal. Remove the call, helper, and declaration. Signed-off-by: Zain Aboobacker <zainaboobacker33@gmail.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: tw68: Convert to DEFINE_SIMPLE_DEV_PM_OPS()Triet Hoang
Convert the deprecated SIMPLE_DEV_PM_OPS to DEFINE_SIMPLE_DEV_PM_OPS and pm_sleep_ptr(). This lets us drop the __maybe_unused annotations from its suspend and resume callbacks, also reduces kernel size in case CONFIG_PM or CONFIG_PM_SLEEP is disabled. Signed-off-by: Triet Hoang <triet.hoang.dev@gmail.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: saa7134: Convert to DEFINE_SIMPLE_DEV_PM_OPS()Triet Hoang
Convert the deprecated SIMPLE_DEV_PM_OPS to DEFINE_SIMPLE_DEV_PM_OPS and pm_sleep_ptr(). Signed-off-by: Triet Hoang <triet.hoang.dev@gmail.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: cx88: Convert to DEFINE_SIMPLE_DEV_PM_OPS()Triet Hoang
Convert the deprecated SIMPLE_DEV_PM_OPS to DEFINE_SIMPLE_DEV_PM_OPS and pm_sleep_ptr(). This lets us drop the __maybe_unused annotations from its suspend and resume callbacks, also reduces kernel size in case CONFIG_PM or CONFIG_PM_SLEEP is disabled. Signed-off-by: Triet Hoang <triet.hoang.dev@gmail.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: bttv: Convert to DEFINE_SIMPLE_DEV_PM_OPS()Triet Hoang
Convert the deprecated SIMPLE_DEV_PM_OPS to DEFINE_SIMPLE_DEV_PM_OPS and pm_sleep_ptr(). This lets us drop the __maybe_unused annotations from its suspend and resume callbacks, also reduces kernel size in case CONFIG_PM or CONFIG_PM_SLEEP is disabled. Signed-off-by: Triet Hoang <triet.hoang.dev@gmail.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: usbtv: fix null-pointer dereference on disconnectAleksandr Nogikh
A null-pointer dereference can occur in usb_make_path() when called from usbtv_querycap() (and other ioctl handlers) during device disconnection. Oops: general protection fault, probably for non-canonical address 0xdffffc000000000a: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000050-0x0000000000000057] RIP: 0010:usb_make_path include/linux/usb.h:985 [inline] RIP: 0010:usbtv_querycap+0x9c/0x100 drivers/media/usb/usbtv/usbtv-video.c:612 ... Call Trace: <TASK> v4l_querycap+0x236/0x470 drivers/media/v4l2-core/v4l2-ioctl.c:1106 __video_do_ioctl+0x8af/0xc70 drivers/media/v4l2-core/v4l2-ioctl.c:3133 video_usercopy+0x860/0x1430 drivers/media/v4l2-core/v4l2-ioctl.c:3475 v4l2_ioctl+0x18d/0x1e0 drivers/media/v4l2-core/v4l2-dev.c:366 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:597 [inline] __se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x174/0x580 arch/x86/entry/syscall_64.c:94 This happens due to a race condition between the USB device disconnect routine (usbtv_disconnect()) and V4L2 ioctls. When the device is disconnected, usbtv_disconnect() sets usbtv->udev = NULL without holding the usbtv->v4l2_lock mutex. Concurrently, an ioctl handler like usbtv_querycap() can be executing under the v4l2_lock and attempt to use usbtv->udev, leading to a crash. To fix this, move the usbtv->udev = NULL assignment into usbtv_video_free() and protect it with mutex_lock(&usbtv->v4l2_lock). This ensures that no non-queue ioctl handler can run concurrently with the pointer being nullified. If an ioctl is already running, the mutex will block the disconnect path until the ioctl finishes. If an ioctl is blocked waiting for the lock, it will acquire it after the disconnect routine releases it, but will then check video_is_registered() (which was cleared by vb2_video_unregister_device()) and safely return -ENODEV. Acquiring v4l2_lock after vb2_video_unregister_device() avoids reintroducing a historical deadlock issue, and usbtv_audio_free() remains safe as it is called before usbtv_video_free(). Fixes: 65e6a2773d65 ("media: usbtv: Remove useless locks in usbtv_video_free()") Cc: stable@vger.kernel.org Assisted-by: Gemini:gemini-3.6-flash Gemini:gemini-3.1-pro-preview syzbot Reported-by: syzbot+37a57a84893052ab6071@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=37a57a84893052ab6071 Link: https://syzkaller.appspot.com/ai_job?id=5abbe65a-5853-4bc2-9135-5c75f88d51ed Signed-off-by: Aleksandr Nogikh <nogikh@google.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: au0828: Free URBs when starting DVB streaming failsRuoyu Wang
start_urb_transfer() stores each allocated URB in dev->urbs[], but sets urb_streaming only after all URBs have been submitted. If a later URB or transfer buffer allocation fails, earlier entries are left allocated. A submission failure calls stop_urb_transfer(), but that function returns immediately while urb_streaming is false, leaving both submitted and unsubmitted URBs behind. Make stop_urb_transfer() release every populated slot regardless of the streaming flag and clear each slot after release. Route all start errors through this cleanup. usb_kill_urb() safely handles both submitted and unsubmitted URBs, while the existing preallocation check preserves the lifetime of shared transfer buffers. This issue was found by a static analysis checker and confirmed by manual source review. Fixes: 265a6510629a ("V4L/DVB (7621): Add support for Hauppauge HVR950Q/HVR850/FusioHDTV7-USB") Cc: stable@vger.kernel.org Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: gspca: use vb2_video_unregister_device() on disconnectShuangpeng Bai
gspca uses vb2_fop_release(), but gspca_disconnect() only unregisters the video device. If the queue owner closes the device after USB disconnect, vb2_fop_release() releases the queue and invokes gspca_stop_streaming() at that point. gspca_stream_off() calls subdriver stop callbacks and usb_set_interface() through gspca_dev->dev. By the time the late close runs, the USB core can have freed the usb_device, resulting in a use-after-free. This was observed as a KASAN use-after-free in sd_stopN(). Use vb2_video_unregister_device() so the queue is released and streaming is stopped synchronously during disconnect, while the usb_device is still valid. Since the helper takes the queue lock, which is usb_lock, call it after dropping that lock. Fixes: f729ef5796d8 ("media: videobuf2-v4l2.c: add vb2_video_unregister_device helper function") Cc: stable@vger.kernel.org # 5.10.x Suggested-by: Hans Verkuil <hverkuil@kernel.org> Signed-off-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: au0828: fix use-after-free in bulk_timeout timer on disconnectFan Wu
start_urb_transfer() arms dev->bulk_timeout, whose callback au0828_bulk_timeout() queues dev->restart_streaming; that work in turn calls start_urb_transfer() and re-arms the timer. au0828_dvb_unregister() cancels restart_streaming on disconnect but does not sync bulk_timeout. au0828_usb_release() then frees dev with kfree(), so a timer still armed or pending at that point can fire after the free and dereference dev through timer_container_of(). Sync the timer with timer_shutdown_sync() before cancel_work_sync(). The timer callback queues the work, so the timer must be stopped first; the shutdown variant is needed because the work re-arms the timer through start_urb_transfer(). The dvb->frontend == NULL early return guards the register-failure path where the timer was never set up. This bug was found by static analysis. Fixes: 53460c53b761 ("[media] au0828: Add timer to restart TS stream if no data arrives on bulk endpoint") Cc: stable@vger.kernel.org Assisted-by: Codex:gpt-5.6 Signed-off-by: Fan Wu <fanwu01@zju.edu.cn> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
12 daysmedia: cx23885: Fix use-after-free in cx23885_finidev due to race conditionPei Xiao
In cx23885_v4l2_dev_notify_init, &dev->cx25840_work is bound with cx23885_av_work_handler, and &dev->ir_rx_work and &dev->ir_tx_work are bound with cx23885_ir_rx_work_handler and cx23885_ir_tx_work_handler. cx23885_irq can schedule these works on system_wq when an AV_CORE interrupt is received, and the IR subdevice can also schedule the IR works from its interrupt service routine via the v4l2_device notify callback. If we remove the device, cx23885_finidev makes cleanup and the memory allocated for dev is released by kfree(dev), while the works mentioned above may still be pending or running. The sequence of operations that may lead to a UAF bug is as follows: CPU0 CPU1 | cx23885_irq | schedule_work(&dev->cx25840_work) cx23885_finidev | cx23885_input_fini(dev) | cx23885_ir_fini(dev) | cx23885_shutdown(dev) | free_irq(pci_dev->irq, dev) | pci_disable_device(pci_dev) | cx23885_dev_unregister(dev) | v4l2_device_unregister(v4l2_dev) | kfree(dev) | // dev is freed | | cx23885_av_work_handler | // use dev (use-after-free) Fix it by canceling the works after the IRQ handler that can schedule them has been stopped, and before proceeding with the remaining cleanup in cx23885_finidev. Note that the flush_work() calls in cx23885_input_ir_stop() do not close this race: they only wait for works that are already queued or running at that moment, they do not prevent the IRQ handler, which is still registered at that point, from scheduling the works again afterwards, and they are skipped entirely when dev->sd_ir is NULL. The cancel_work_sync() calls are therefore placed after free_irq(), the only point at which no new work can be scheduled. Fixes: e5514f104d87 ("V4L/DVB: cx23885: Move AV Core irq handling to a work handler") Cc: stable@vger.kernel.org Assisted-by: Codex:deepseek-v4-flash Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>