From: Andrzej Hajda <andrzej.hajda@intel.com>
To: Yuan Can <yuancan@huawei.com>,
peter.senna@gmail.com, martin.donnelly@ge.com,
martyn.welch@collabora.co.uk, neil.armstrong@linaro.org,
robert.foss@linaro.org, Laurent.pinchart@ideasonboard.com,
jonas@kwiboo.se, jernej.skrabec@gmail.com, airlied@gmail.com,
daniel@ffwll.ch, architt@codeaurora.org,
dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/bridge: megachips: Fix error handling in i2c_register_driver()
Date: Tue, 8 Nov 2022 09:50:00 +0100 [thread overview]
Message-ID: <aa5ffd76-d95a-8aea-ddc9-eaf8e95a73ce@intel.com> (raw)
In-Reply-To: <20221108082956.35802-1-yuancan@huawei.com>
On 08.11.2022 09:29, Yuan Can wrote:
> A problem about insmod megachips-stdpxxxx-ge-b850v3-fw.ko failed is
> triggered with the following log given:
>
> [ 4497.981497] Error: Driver 'stdp4028-ge-b850v3-fw' is already registered, aborting...
> insmod: ERROR: could not insert module megachips-stdpxxxx-ge-b850v3-fw.ko: Device or resource busy
>
> The reason is that stdpxxxx_ge_b850v3_init() returns i2c_add_driver()
> directly without checking its return value, if i2c_add_driver() failed,
> it returns without calling i2c_del_driver() on the previous i2c driver,
> resulting the megachips-stdpxxxx-ge-b850v3-fw can never be installed
> later.
> A simple call graph is shown as below:
>
> stdpxxxx_ge_b850v3_init()
> i2c_add_driver(&stdp4028_ge_b850v3_fw_driver)
> i2c_add_driver(&stdp2690_ge_b850v3_fw_driver)
> i2c_register_driver()
> driver_register()
> bus_add_driver()
> priv = kzalloc(...) # OOM happened
> # return without delete stdp4028_ge_b850v3_fw_driver
>
> Fix by calling i2c_del_driver() on stdp4028_ge_b850v3_fw_driver when
> i2c_add_driver() returns error.
>
> Fixes: fcfa0ddc18ed ("drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> ---
> drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> index 97359f807bfc..0d037eeefcf3 100644
> --- a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> +++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> @@ -440,7 +440,13 @@ static int __init stdpxxxx_ge_b850v3_init(void)
> if (ret)
> return ret;
>
> - return i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
> + ret = i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
> + if (ret) {
> + i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
> + return ret;
> + }
> +
> + return 0;
Could be:
ret = i2c_add_driver(&stdp2690_ge_b850v3_fw_driver);
if (ret)
i2c_del_driver(&stdp4028_ge_b850v3_fw_driver);
return ret;
Up to you. Anyway:
Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>
Regards
Andrzej
> }
> module_init(stdpxxxx_ge_b850v3_init);
>
next prev parent reply other threads:[~2022-11-08 8:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-08 8:29 [PATCH] drm/bridge: megachips: Fix error handling in i2c_register_driver() Yuan Can
2022-11-08 8:50 ` Andrzej Hajda [this message]
2022-11-08 9:08 ` Yuan Can
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=aa5ffd76-d95a-8aea-ddc9-eaf8e95a73ce@intel.com \
--to=andrzej.hajda@intel.com \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=airlied@gmail.com \
--cc=architt@codeaurora.org \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=jernej.skrabec@gmail.com \
--cc=jonas@kwiboo.se \
--cc=martin.donnelly@ge.com \
--cc=martyn.welch@collabora.co.uk \
--cc=neil.armstrong@linaro.org \
--cc=peter.senna@gmail.com \
--cc=robert.foss@linaro.org \
--cc=yuancan@huawei.com \
/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;
as well as URLs for NNTP newsgroup(s).