public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Fengguang Wu <fengguang.wu@intel.com>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Greg Kroah-Hartman <gregkh@suse.de>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: NULL pointer dereference in iio_buffer_register()
Date: Tue, 31 Jul 2012 21:04:42 +0800	[thread overview]
Message-ID: <20120731130442.GA19051@localhost> (raw)
In-Reply-To: <5017D843.8070001@metafoo.de>

On Tue, Jul 31, 2012 at 03:06:11PM +0200, Lars-Peter Clausen wrote:
> On 07/31/2012 02:55 PM, Fengguang Wu wrote:
> >>> The panic happens while trying to dereference the NULL indio_dev->buffer:
> >>>
> >>>         266 int iio_buffer_register(struct iio_dev *indio_dev,
> >>>         267                         const struct iio_chan_spec *channels,
> >>>         268                         int num_channels)
> >>>         269 {  
> >>>         270         struct iio_dev_attr *p;
> >>>         271         struct attribute **attr;
> >>>         272         struct iio_buffer *buffer = indio_dev->buffer;
> >>>         273         int ret, i, attrn, attrcount, attrcount_orig = 0;
> >>>         274 
> >>> ==>     275         if (buffer->attrs)
> >>>         276                 indio_dev->groups[indio_dev->groupcounter++] = buffer->attrs;
> >>>
> >>> iio_dummy_probe() has the code to configure that buffer, however
> >>> iio_simple_dummy_configure_buffer() is defined to do nothing on
> >>> !CONFIG_IIO_SIMPLE_DUMMY_BUFFER..
> >>>
> >>>         448         /* Configure buffered capture support. */
> >>> ==>     449         ret = iio_simple_dummy_configure_buffer(indio_dev);
> >>>         450         if (ret < 0)
> >>>         451                 goto error_unregister_events;
> >>>         452 
> >>>         453         /*
> >>>         454          * Register the channels with the buffer, but avoid the output
> >>>         455          * channel being registered by reducing the number of channels by 1.
> >>>         456          */
> >>>         457         ret = iio_buffer_register(indio_dev, iio_dummy_channels, 5);
> >>>         458         if (ret < 0)
> >>>         459                 goto error_unconfigure_buffer;
> >>>
> >>> Any ideas to fix it?
> >>>
> >>
> >> Hi,
> >>
> >> I think the best would be to move the iio_buffer_register to
> >> iio_simple_dummy_configure_buffer.
> > 
> > Lars, thanks for the quick reply! Hmm, that looks more like a code
> > refactor recommendation than fix ;)  In the simplest form, can the
> > bug fixed like this?
> > 
> >   static inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
> >   {
> > -         return 0;
> > +         return -1;
> >   };
> > 
> 
> No, we want iio_simple_dummy_configure_buffer to be a noop if buffer support
> is disabled, since the driver works fine without it. Except for the issue
> you discovered. This issue only appears if CONFIG_IIO_BUFFER=y and
> CONFIG_IIO_SIMPLE_DUMMY_BUFFER=n. E.g. if both are not set the driver works
> fine without buffers.

OK.

> I can prepare a patch which moves the iio_buffer_register to
> iio_simple_dummy_configure_buffer if you want to.

That would be good, thank you very much!

Thanks,
Fengguang

      reply	other threads:[~2012-07-31 13:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-08 11:53 NULL pointer dereference in iio_buffer_register() Fengguang Wu
2012-07-31 10:31 ` Fengguang Wu
2012-07-31 12:42   ` Lars-Peter Clausen
2012-07-31 12:55     ` Fengguang Wu
2012-07-31 13:06       ` Lars-Peter Clausen
2012-07-31 13:04         ` Fengguang Wu [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=20120731130442.GA19051@localhost \
    --to=fengguang.wu@intel.com \
    --cc=gregkh@suse.de \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-kernel@vger.kernel.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