[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241101172926.4e8e3f43@jic23-huawei>
Date: Fri, 1 Nov 2024 17:29:26 +0000
From: Jonathan Cameron <jic23@...nel.org>
To: Pei Xiao <xiaopei01@...inos.cn>
Cc: liambeguin@...il.com, lars@...afoo.de, linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org, xiaopeitux@...mail.com
Subject: Re: [PATCH] iio: test : check null return of kunit_kmalloc in
iio_rescale_test_scale
On Wed, 30 Oct 2024 11:48:54 +0800
Pei Xiao <xiaopei01@...inos.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@...inos.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;
Powered by blists - more mailing lists