* [PATCH] iio: test : check null return of kunit_kmalloc in iio_rescale_test_scale
@ 2024-10-30 3:48 Pei Xiao
2024-11-01 17:29 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: Pei Xiao @ 2024-10-30 3:48 UTC (permalink / raw)
To: liambeguin; +Cc: xiaopei01, jic23, lars, linux-iio, linux-kernel, xiaopeitux
kunit_kmalloc may fail, return value might be NULL and will cause
NULL pointer dereference.Add KUNIT_ASSERT_NOT_ERR_OR_NULL fix it.
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;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: test : check null return of kunit_kmalloc in iio_rescale_test_scale
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
2024-11-04 1:14 ` Pei Xiao
0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2024-11-01 17:29 UTC (permalink / raw)
To: Pei Xiao; +Cc: liambeguin, lars, linux-iio, linux-kernel, xiaopeitux
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;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: test : check null return of kunit_kmalloc in iio_rescale_test_scale
2024-11-01 17:29 ` Jonathan Cameron
@ 2024-11-04 1:14 ` Pei Xiao
2024-11-23 14:29 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: Pei Xiao @ 2024-11-04 1:14 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: liambeguin, lars, linux-iio, linux-kernel, xiaopeitux
On 2024/11/2 01:29, Jonathan Cameron Wrote:
> 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?
As you thought, initially I felt that we should use
KUNIT_ASSERT_NOT_NULL. However, when I used grep
KUNIT_ASSERT_NOT_ERR_OR_NULL -nr drivers/iio/test/, I found that the
drivers/iio/test/ directory exclusively uses
KUNIT_ASSERT_NOT_ERR_OR_NULL instead of KUNIT_ASSERT_NOT_NULL. To
maintain consistency, I have changed it to KUNIT_ASSERT_NOT_ERR_OR_NULL.
drivers/iio/test/iio-test-format.c:22:
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
drivers/iio/test/iio-test-format.c:52:
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
drivers/iio/test/iio-test-format.c:113:
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
drivers/iio/test/iio-test-format.c:153:
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
drivers/iio/test/iio-test-format.c:193:
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
drivers/iio/test/iio-test-format.c:208:
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
>>
>> 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;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio: test : check null return of kunit_kmalloc in iio_rescale_test_scale
2024-11-04 1:14 ` Pei Xiao
@ 2024-11-23 14:29 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2024-11-23 14:29 UTC (permalink / raw)
To: Pei Xiao; +Cc: liambeguin, lars, linux-iio, linux-kernel, xiaopeitux
On Mon, 4 Nov 2024 09:14:45 +0800
Pei Xiao <xiaopei01@kylinos.cn> wrote:
> On 2024/11/2 01:29, Jonathan Cameron Wrote:
> > 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?
> As you thought, initially I felt that we should use
> KUNIT_ASSERT_NOT_NULL. However, when I used grep
> KUNIT_ASSERT_NOT_ERR_OR_NULL -nr drivers/iio/test/, I found that the
> drivers/iio/test/ directory exclusively uses
> KUNIT_ASSERT_NOT_ERR_OR_NULL instead of KUNIT_ASSERT_NOT_NULL. To
> maintain consistency, I have changed it to KUNIT_ASSERT_NOT_ERR_OR_NULL.
>
> drivers/iio/test/iio-test-format.c:22:
> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
> drivers/iio/test/iio-test-format.c:52:
> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
> drivers/iio/test/iio-test-format.c:113:
> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
> drivers/iio/test/iio-test-format.c:153:
> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
> drivers/iio/test/iio-test-format.c:193:
> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
> drivers/iio/test/iio-test-format.c:208:
> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
Ok. May be worth a follow up to tidy that up. A couple more cases do no real harm.
Applied to the fixes-togreg branch of iio.git.
Thanks,
Jonathan
> >>
> >> 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;
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-11-23 14:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2024-11-04 1:14 ` Pei Xiao
2024-11-23 14:29 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox