From: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
To: Chen-Yu Tsai <wenst@chromium.org>
Cc: chunkuang.hu@kernel.org, p.zabel@pengutronix.de,
airlied@gmail.com, simona@ffwll.ch, matthias.bgg@gmail.com,
nancy.lin@mediatek.com, ck.hu@mediatek.com, djkurtz@chromium.org,
littlecvr@chromium.org, bibby.hsieh@mediatek.com,
dri-devel@lists.freedesktop.org,
linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, kernel@collabora.com
Subject: Re: [PATCH v1 4/5] drm/mediatek: mtk_disp_ovl: Enable/disable interrupt on bind/unbind
Date: Wed, 2 Apr 2025 12:08:50 +0200 [thread overview]
Message-ID: <608f25af-69dc-455d-b382-aaa3cb2d9578@collabora.com> (raw)
In-Reply-To: <CAGXv+5E1qShE1LqgFL6rrgRzjwFUPoBqYdhO-sgNzmMqQsMS0Q@mail.gmail.com>
Il 02/04/25 11:38, Chen-Yu Tsai ha scritto:
> On Wed, Apr 2, 2025 at 4:36 PM AngeloGioacchino Del Regno
> <angelogioacchino.delregno@collabora.com> wrote:
>>
>> The OVL driver is installing an ISR in the probe function but, if
>> the component is not bound yet, the interrupt handler may call the
>> vblank_cb ahead of time (while probing other drivers) or too late
>> (while removing other drivers), possibly accessing memory that it
>> should not try to access by reusing stale pointers.
>>
>> In order to fix this, add a new `irq` member to struct mtk_disp_ovl
>> and then set the NOAUTOEN flag to the irq before installing the ISR
>> to manually call enable_irq() and disable_irq() in the bind and
>> unbind callbacks respectively.
>>
>> Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.")
>> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
>> ---
>> drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 19 +++++++++++++------
>> 1 file changed, 13 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
>> index df82cea4bb79..1bff3a1273f6 100644
>> --- a/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
>> +++ b/drivers/gpu/drm/mediatek/mtk_disp_ovl.c
>> @@ -161,6 +161,7 @@ struct mtk_disp_ovl {
>> struct drm_crtc *crtc;
>> struct clk *clk;
>> void __iomem *regs;
>> + int irq;
>> struct cmdq_client_reg cmdq_reg;
>> const struct mtk_disp_ovl_data *data;
>> void (*vblank_cb)(void *data);
>> @@ -587,12 +588,18 @@ void mtk_ovl_bgclr_in_off(struct device *dev)
>> static int mtk_disp_ovl_bind(struct device *dev, struct device *master,
>> void *data)
>> {
>> + struct mtk_disp_ovl *priv = dev_get_drvdata(dev);
>> +
>> + enable_irq(priv->irq);
>> return 0;
>> }
>>
>> static void mtk_disp_ovl_unbind(struct device *dev, struct device *master,
>> void *data)
>> {
>> + struct mtk_disp_ovl *priv = dev_get_drvdata(dev);
>> +
>> + disable_irq(priv->irq);
>> }
>>
>> static const struct component_ops mtk_disp_ovl_component_ops = {
>> @@ -605,16 +612,15 @@ static int mtk_disp_ovl_probe(struct platform_device *pdev)
>> struct device *dev = &pdev->dev;
>> struct mtk_disp_ovl *priv;
>> struct resource *res;
>> - int irq;
>> int ret;
>>
>> priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>> if (!priv)
>> return -ENOMEM;
>>
>> - irq = platform_get_irq(pdev, 0);
>> - if (irq < 0)
>> - return irq;
>> + priv->irq = platform_get_irq(pdev, 0);
>> + if (priv->irq < 0)
>> + return priv->irq;
>>
>> priv->clk = devm_clk_get(dev, NULL);
>> if (IS_ERR(priv->clk))
>> @@ -635,10 +641,11 @@ static int mtk_disp_ovl_probe(struct platform_device *pdev)
>> priv->data = of_device_get_match_data(dev);
>> platform_set_drvdata(pdev, priv);
>>
>> - ret = devm_request_irq(dev, irq, mtk_disp_ovl_irq_handler,
>> + irq_set_status_flags(priv->irq, IRQ_NOAUTOEN);
>> + ret = devm_request_irq(dev, priv->irq, mtk_disp_ovl_irq_handler,
>> IRQF_TRIGGER_NONE, dev_name(dev), priv);
>
> Use IRQF_NO_AUTOEN here? Also, IRQF_TRIGGER_NONE can be dropped.
>
Yeah, nice one. Thanks!
Cheers,
Angelo
> Make sense otherwise.
>
> ChenYu
>
>> if (ret < 0)
>> - return dev_err_probe(dev, ret, "Failed to request irq %d\n", irq);
>> + return dev_err_probe(dev, ret, "Failed to request irq %d\n", priv->irq);
>>
>> pm_runtime_enable(dev);
>>
>> --
>> 2.48.1
>>
next prev parent reply other threads:[~2025-04-02 10:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-02 8:36 [PATCH v1 0/5] drm/mediatek: Cleanups and sanitization AngeloGioacchino Del Regno
2025-04-02 8:36 ` [PATCH v1 1/5] drm/mediatek: mtk_drm_drv: Fix kobject put for mtk_mutex device ptr AngeloGioacchino Del Regno
2025-04-02 10:14 ` Chen-Yu Tsai
2025-04-02 8:36 ` [PATCH v1 2/5] drm/mediatek: Fix kobject put for component sub-drivers AngeloGioacchino Del Regno
2025-04-02 10:18 ` Chen-Yu Tsai
2025-04-02 8:36 ` [PATCH v1 3/5] drm/mediatek: mtk_drm_drv: Unbind secondary mmsys components on err AngeloGioacchino Del Regno
2025-04-02 10:19 ` Chen-Yu Tsai
2025-04-02 8:36 ` [PATCH v1 4/5] drm/mediatek: mtk_disp_ovl: Enable/disable interrupt on bind/unbind AngeloGioacchino Del Regno
2025-04-02 9:38 ` Chen-Yu Tsai
2025-04-02 10:08 ` AngeloGioacchino Del Regno [this message]
2025-04-02 8:36 ` [PATCH v1 5/5] drm/mediatek: mtk_disp_rdma: " AngeloGioacchino Del Regno
2025-04-02 9:42 ` Chen-Yu Tsai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=608f25af-69dc-455d-b382-aaa3cb2d9578@collabora.com \
--to=angelogioacchino.delregno@collabora.com \
--cc=airlied@gmail.com \
--cc=bibby.hsieh@mediatek.com \
--cc=chunkuang.hu@kernel.org \
--cc=ck.hu@mediatek.com \
--cc=djkurtz@chromium.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=kernel@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=littlecvr@chromium.org \
--cc=matthias.bgg@gmail.com \
--cc=nancy.lin@mediatek.com \
--cc=p.zabel@pengutronix.de \
--cc=simona@ffwll.ch \
--cc=wenst@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®