All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean Delvare <khali@linux-fr.org>
To: Timur Tabi <timur@freescale.com>
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH] ASoC: Fix cs4270 error path
Date: Sat, 27 Sep 2008 18:09:10 +0200	[thread overview]
Message-ID: <20080927180910.1ab7eb63@hyperion.delvare> (raw)
In-Reply-To: <ed82fe3e0809221335w4da49a21jcce3f676d2f75a54@mail.gmail.com>

Hi Timur,

On Mon, 22 Sep 2008 15:35:17 -0500, Timur Tabi wrote:
> Sorry I didn't get to this earlier.  I just fell off my radar.
> 
> On Sun, Aug 31, 2008 at 7:42 AM, Jean Delvare <khali@linux-fr.org> wrote:
> > The error path in cs4270_probe/cs4270_remove is pretty broken:
> > * If cs4270_probe fails, codec is leaked.
> > * If snd_soc_register_card fails, cs4270_i2c_driver stays registered.
> 
> So far, so good.
> 
> > * If I2C support is enabled but no I2C device is found, i2c_del_driver
> >  is never called (neither in cs4270_probe nor in cs4270_remove.)
> 
> Hmm... The only time that can happen is if the device tree is wrong or
> the hardware is broken.

The whole point of error paths is to handle cases that were not
supposed to happen.

> (...)  This means that cs4270_i2c_probe() will
> return an error.  What does i2c_add_driver() return in that case?

As per the device driver model, the success or failure of device probes
has zero influence on drivers. So, yes, i2c_add_driver() still succeeds
and returns 0.

> (...)  If
> it still returns 0, then control_data will be NULL, but with your
> patch, i2c_del_driver() will still be called.

Of course, it will be. It has to. This is exactly the bug I am fixing!
If i2c_add_driver() succeeds then i2c_del_driver() must be called in the
cleanup path. It's really that easy. Whether an I2C device was found or
not, must not influence that.

> 
> Also, I think there's a bug in cs4270_i2c_probe(), where it will call
> i2c_detach_driver() if it fails.  It shouldn't do that.  This is also
> gated on codec->control_data, so it's a related bug.

You are right, this is a bug. Apparently you forgot the error path when
converting the driver to a new-style i2c driver. A few lines below,
there's also:
	kfree(i2c_client);
which should be removed.

I disagree that this is related with my initial patch though. It's a
different error path, and it's also broken, but that's hardly enough to
make both bugs "related". So I'll send a separate patch.

> 
> Lastly, you may need to rebase the patch, since the code's changed.

My patch still applies fine (with offset, but that's OK), so I fail to
see why I would need to rebase it.

-- 
Jean Delvare

  reply	other threads:[~2008-09-27 16:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-31 12:42 [PATCH] ASoC: Fix cs4270 error path Jean Delvare
2008-09-22 12:29 ` Jean Delvare
2008-09-22 20:35 ` Timur Tabi
2008-09-27 16:09   ` Jean Delvare [this message]
2008-09-29 13:42 ` Timur Tabi
2008-09-29 13:48   ` Takashi Iwai
2008-09-30  8:31     ` Jean Delvare
2008-09-30  8:53       ` Takashi Iwai
2008-09-30  9:38         ` Jean Delvare
2008-09-30 11:08           ` Takashi Iwai
2008-09-30 14:25         ` Timur Tabi
2008-09-30 14:49           ` Takashi Iwai
2008-09-30 14:56             ` Timur Tabi
2008-09-30 15:03               ` Takashi Iwai
  -- strict thread matches above, loose matches on Subject: below --
2008-09-30  9:40 Jean Delvare

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=20080927180910.1ab7eb63@hyperion.delvare \
    --to=khali@linux-fr.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=timur@freescale.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.