Skip to content

Commit

Permalink
iio: test : check null return of kunit_kmalloc in iio_rescale_test_scale
Browse files Browse the repository at this point in the history
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: 8e74a48 ("iio: test: add basic tests for the iio-rescale driver")
Link: https://patch.msgid.link/ecd56a85e54a96c2f0313c114075a21a76071ea2.1730259869.git.xiaopei01@kylinos.cn
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
  • Loading branch information
Pei Xiao authored and Jonathan Cameron committed Dec 7, 2024
1 parent 4be339a commit aaa90d0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/iio/test/iio-test-rescale.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit aaa90d0

Please sign in to comment.