Linux-IIO Archive on lore.kernel.org
 help / Atom feed
* [PATCH] iio: dummy_evgen: check iio_evgen in iio_dummy_evgen_free()
@ 2019-05-09  2:04 Kefeng Wang
  2019-05-11  8:58 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Kefeng Wang @ 2019-05-09  2:04 UTC (permalink / raw)
  To: Jonathan Cameron, Jonathan Cameron, linux-iio, linux-kernel,
	Rodrigo Siqueira
  Cc: Kefeng Wang, Hulk Robot

if iio_dummy_evgen_create() fails, iio_evgen should be NULL, when call
iio_evgen_release() to cleanup, it throws some warning and could cause
double free.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 drivers/iio/dummy/iio_dummy_evgen.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/iio/dummy/iio_dummy_evgen.c b/drivers/iio/dummy/iio_dummy_evgen.c
index c6033e341963..2327b5f52086 100644
--- a/drivers/iio/dummy/iio_dummy_evgen.c
+++ b/drivers/iio/dummy/iio_dummy_evgen.c
@@ -58,6 +58,7 @@ static int iio_dummy_evgen_create(void)
 	ret = irq_sim_init(&iio_evgen->irq_sim, IIO_EVENTGEN_NO);
 	if (ret < 0) {
 		kfree(iio_evgen);
+		iio_evgen = NULL;
 		return ret;
 	}
 
@@ -118,6 +119,9 @@ EXPORT_SYMBOL_GPL(iio_dummy_evgen_get_regs);
 
 static void iio_dummy_evgen_free(void)
 {
+	if (!iio_evgen)
+		return;
+
 	irq_sim_fini(&iio_evgen->irq_sim);
 	kfree(iio_evgen);
 }
-- 
2.20.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] iio: dummy_evgen: check iio_evgen in iio_dummy_evgen_free()
  2019-05-09  2:04 [PATCH] iio: dummy_evgen: check iio_evgen in iio_dummy_evgen_free() Kefeng Wang
@ 2019-05-11  8:58 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2019-05-11  8:58 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Jonathan Cameron, linux-iio, linux-kernel, Rodrigo Siqueira, Hulk Robot

On Thu, 9 May 2019 10:04:47 +0800
Kefeng Wang <wangkefeng.wang@huawei.com> wrote:

> if iio_dummy_evgen_create() fails, iio_evgen should be NULL, when call
> iio_evgen_release() to cleanup, it throws some warning and could cause
> double free.
> 
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Hi Kefeng,

I'm not seeing a path to be able to trigger this.
iio_dummy_evgen_create is called only in the module_init.
If it fails, then the init fails before the device
initialization call is made.

How would we then be running the device release call
in order to end up freeing this again?

So I think this is a false positive but perhaps there is
a path that I am missing.

Jonathan

> ---
>  drivers/iio/dummy/iio_dummy_evgen.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/iio/dummy/iio_dummy_evgen.c b/drivers/iio/dummy/iio_dummy_evgen.c
> index c6033e341963..2327b5f52086 100644
> --- a/drivers/iio/dummy/iio_dummy_evgen.c
> +++ b/drivers/iio/dummy/iio_dummy_evgen.c
> @@ -58,6 +58,7 @@ static int iio_dummy_evgen_create(void)
>  	ret = irq_sim_init(&iio_evgen->irq_sim, IIO_EVENTGEN_NO);
>  	if (ret < 0) {
>  		kfree(iio_evgen);
> +		iio_evgen = NULL;
>  		return ret;
>  	}
>  
> @@ -118,6 +119,9 @@ EXPORT_SYMBOL_GPL(iio_dummy_evgen_get_regs);
>  
>  static void iio_dummy_evgen_free(void)
>  {
> +	if (!iio_evgen)
> +		return;
> +
>  	irq_sim_fini(&iio_evgen->irq_sim);
>  	kfree(iio_evgen);
>  }


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-09  2:04 [PATCH] iio: dummy_evgen: check iio_evgen in iio_dummy_evgen_free() Kefeng Wang
2019-05-11  8:58 ` Jonathan Cameron

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org linux-iio@archiver.kernel.org
	public-inbox-index linux-iio


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/ public-inbox