dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Ian Ray <ian.ray@ge.com>
To: Yuan Can <yuancan@huawei.com>
Cc: neil.armstrong@linaro.org, architt@codeaurora.org,
	jernej.skrabec@gmail.com, martyn.welch@collabora.co.uk,
	jonas@kwiboo.se, dri-devel@lists.freedesktop.org,
	peter.senna@gmail.com, robert.foss@linaro.org,
	Laurent.pinchart@ideasonboard.com, andrzej.hajda@intel.com,
	martin.donnelly@ge.com
Subject: Re: [PATCH v2] drm/bridge: megachips: Fix error handling in i2c_register_driver()
Date: Wed, 23 Nov 2022 08:40:17 +0200	[thread overview]
Message-ID: <20221123064017.GA4408@zoo6.em.health.ge.com> (raw)
In-Reply-To: <20221108091226.114524-1-yuancan@huawei.com>

On Tue, Nov 08, 2022 at 09:12:26AM +0000, 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.
> 

Thank you!

> Fixes: fcfa0ddc18ed ("drm/bridge: Drivers for megachips-stdpxxxx-ge-b850v3-fw (LVDS-DP++)")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>

Tested-by: Ian Ray <ian.ray@ge.com>

> ---
> Changes in v2:
> - Add Andrzej's Reviewed-by
> - Change to the new error return style suggested by Andrzej
> 
>  drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c | 6 +++++-
>  1 file changed, 5 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..cbfa05a6767b 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,11 @@ 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;
>  }
>  module_init(stdpxxxx_ge_b850v3_init);
>  
> -- 
> 2.17.1
> 

  reply	other threads:[~2022-11-23  8:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-08  9:12 [PATCH v2] drm/bridge: megachips: Fix error handling in i2c_register_driver() Yuan Can
2022-11-23  6:40 ` Ian Ray [this message]
2022-11-29 16:58   ` Robert Foss

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=20221123064017.GA4408@zoo6.em.health.ge.com \
    --to=ian.ray@ge.com \
    --cc=Laurent.pinchart@ideasonboard.com \
    --cc=andrzej.hajda@intel.com \
    --cc=architt@codeaurora.org \
    --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).