Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Pei Xiao <xiaopei01@kylinos.cn>
Cc: liambeguin@gmail.com, lars@metafoo.de, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org, xiaopeitux@foxmail.com
Subject: Re: [PATCH] iio: test : check null return of kunit_kmalloc in iio_rescale_test_scale
Date: Fri, 1 Nov 2024 17:29:26 +0000	[thread overview]
Message-ID: <20241101172926.4e8e3f43@jic23-huawei> (raw)
In-Reply-To: <ecd56a85e54a96c2f0313c114075a21a76071ea2.1730259869.git.xiaopei01@kylinos.cn>

On Wed, 30 Oct 2024 11:48:54 +0800
Pei Xiao <xiaopei01@kylinos.cn> wrote:

> kunit_kmalloc may fail, return value might be NULL and will cause
> NULL pointer dereference.Add KUNIT_ASSERT_NOT_ERR_OR_NULL fix it.
Can it be an error?  If not why not use KUNIT_ASSERT_NOT_NULL?
> 
> Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
> Fixes: 8e74a48d17d5 ("iio: test: add basic tests for the iio-rescale driver")
> ---
>  drivers/iio/test/iio-test-rescale.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/iio/test/iio-test-rescale.c b/drivers/iio/test/iio-test-rescale.c
> index 31ee55a6faed..11bfff6636a3 100644
> --- a/drivers/iio/test/iio-test-rescale.c
> +++ b/drivers/iio/test/iio-test-rescale.c
> @@ -652,6 +652,8 @@ static void iio_rescale_test_scale(struct kunit *test)
>  	int rel_ppm;
>  	int ret;
>  
> +	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buff);
> +
>  	rescale.numerator = t->numerator;
>  	rescale.denominator = t->denominator;
>  	rescale.offset = t->offset;
> @@ -681,6 +683,8 @@ static void iio_rescale_test_offset(struct kunit *test)
>  	int values[2];
>  	int ret;
>  
> +	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buff_off);
> +
>  	rescale.numerator = t->numerator;
>  	rescale.denominator = t->denominator;
>  	rescale.offset = t->offset;


  reply	other threads:[~2024-11-01 17:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-30  3:48 [PATCH] iio: test : check null return of kunit_kmalloc in iio_rescale_test_scale Pei Xiao
2024-11-01 17:29 ` Jonathan Cameron [this message]
2024-11-04  1:14   ` Pei Xiao
2024-11-23 14:29     ` Jonathan Cameron

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=20241101172926.4e8e3f43@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=liambeguin@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xiaopei01@kylinos.cn \
    --cc=xiaopeitux@foxmail.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