Skip to content

Commit 0c91bb4

Browse files
Dmitriy Ulitingregkh
authored andcommitted
media: stm32: Potential NULL pointer dereference in dcmi_irq_thread()
[ Upstream commit 548fa43 ] At the moment of enabling irq handling: 1922 ret = devm_request_threaded_irq(&pdev->dev, irq, dcmi_irq_callback, 1923 dcmi_irq_thread, IRQF_ONESHOT, 1924 dev_name(&pdev->dev), dcmi); there is still uninitialized field sd_format of struct stm32_dcmi *dcmi. If an interrupt occurs in the interval between the installation of the interrupt handler and the initialization of this field, NULL pointer dereference happens. This field is dereferenced in the handler function without any check: 457 if (dcmi->sd_format->fourcc == V4L2_PIX_FMT_JPEG && 458 dcmi->misr & IT_FRAME) { The patch moves interrupt handler installation after initialization of the sd_format field that happens in dcmi_graph_notify_complete() via dcmi_set_default_fmt(). Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Dmitriy Ulitin <ulitin@ispras.ru> Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 309ea22 commit 0c91bb4

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

‎drivers/media/platform/stm32/stm32-dcmi.c‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct stm32_dcmi {
135135
int sequence;
136136
struct list_head buffers;
137137
struct dcmi_buf *active;
138+
int irq;
138139

139140
struct v4l2_device v4l2_dev;
140141
struct video_device *vdev;
@@ -1720,6 +1721,14 @@ static int dcmi_graph_notify_complete(struct v4l2_async_notifier *notifier)
17201721
return ret;
17211722
}
17221723

1724+
ret = devm_request_threaded_irq(dcmi->dev, dcmi->irq, dcmi_irq_callback,
1725+
dcmi_irq_thread, IRQF_ONESHOT,
1726+
dev_name(dcmi->dev), dcmi);
1727+
if (ret) {
1728+
dev_err(dcmi->dev, "Unable to request irq %d\n", dcmi->irq);
1729+
return ret;
1730+
}
1731+
17231732
return 0;
17241733
}
17251734

@@ -1881,6 +1890,8 @@ static int dcmi_probe(struct platform_device *pdev)
18811890
if (irq <= 0)
18821891
return irq ? irq : -ENXIO;
18831892

1893+
dcmi->irq = irq;
1894+
18841895
dcmi->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
18851896
if (!dcmi->res) {
18861897
dev_err(&pdev->dev, "Could not get resource\n");
@@ -1893,14 +1904,6 @@ static int dcmi_probe(struct platform_device *pdev)
18931904
return PTR_ERR(dcmi->regs);
18941905
}
18951906

1896-
ret = devm_request_threaded_irq(&pdev->dev, irq, dcmi_irq_callback,
1897-
dcmi_irq_thread, IRQF_ONESHOT,
1898-
dev_name(&pdev->dev), dcmi);
1899-
if (ret) {
1900-
dev_err(&pdev->dev, "Unable to request irq %d\n", irq);
1901-
return ret;
1902-
}
1903-
19041907
mclk = devm_clk_get(&pdev->dev, "mclk");
19051908
if (IS_ERR(mclk)) {
19061909
if (PTR_ERR(mclk) != -EPROBE_DEFER)

0 commit comments

Comments
 (0)