mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: Hongqi Chen <U202112190@hust.edu.cn>
Cc: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>,
	David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
	Dave Airlie <airlied@redhat.com>, Alan Cox <alan@linux.intel.com>,
	hust-os-kernel-patches@googlegroups.com,
	Dongliang Mu <dzm91@hust.edu.cn>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] gpu: gma500: psb_drv: add missing unwind goto
Date: Mon, 17 Apr 2023 09:37:33 +0300	[thread overview]
Message-ID: <be7cfdac-29bf-47ee-8efa-4a5d06faf165@kili.mountain> (raw)
In-Reply-To: <20230417060105.16411-1-U202112190@hust.edu.cn>

On Mon, Apr 17, 2023 at 02:01:05PM +0800, Hongqi Chen wrote:
> Smatch reports that missing unwind goto in psb_driver_load().
> drivers/gpu/drm/gma500/psb_drv.c:350 psb_driver_load() warn: missing
> unwind goto?
> 
> psb_driver_unload() and psb_driver_load() exist in correspondence, 
> and psb_driver_unload() should be executed when the psb_do_init() 
> fails to initialize.
> 
> Fixes: 5c49fd3aa0ab ("gma500: Add the core DRM files and headers")
> Signed-off-by: Hongqi Chen <U202112190@hust.edu.cn>
> Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
> ---
>  drivers/gpu/drm/gma500/psb_drv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/gma500/psb_drv.c b/drivers/gpu/drm/gma500/psb_drv.c
> index cd9c73f5a64a..b5a276342129 100644
> --- a/drivers/gpu/drm/gma500/psb_drv.c
> +++ b/drivers/gpu/drm/gma500/psb_drv.c
> @@ -347,7 +347,7 @@ static int psb_driver_load(struct drm_device *dev, unsigned long flags)
>  
>  	ret = psb_do_init(dev);
>  	if (ret)
> -		return ret;
> +		goto out_err;

This kind of error handling is called One Magical Cleanup Function.
These functions are always buggy.  My instinct is that it's better to
just return directly and leak resources instead of doing whatever
horrible thing psb_driver_unload() does.

Update:  I started to look at the psb_driver_unload() and the first line
is gma_backlight_exit() which will lead to a crash if
backlight_device_register() fails.

Reviewing One Magical Cleanup Function is a waste of time, easier to
just re-write it.

The problem as well is that in olden days if the probe() function failed
you were screwed and so no one cared about error handling and cleanup.
Who cares about the details when the result is the same (dead system).
But these days we return -EPROBE_DEFER which is not a fatal error and
we're supposed to recover from that without crashing.  So on modern
drivers changing the error path from a leak to a crash has a huge
negative impact.

regards,
dan carpenter


      reply	other threads:[~2023-04-17  6:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-17  6:01 Hongqi Chen
2023-04-17  6:37 ` Dan Carpenter [this message]

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=be7cfdac-29bf-47ee-8efa-4a5d06faf165@kili.mountain \
    --to=error27@gmail.com \
    --cc=U202112190@hust.edu.cn \
    --cc=airlied@gmail.com \
    --cc=airlied@redhat.com \
    --cc=alan@linux.intel.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=dzm91@hust.edu.cn \
    --cc=hust-os-kernel-patches@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patrik.r.jakobsson@gmail.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

all inboxes | Powered by JetHome®