]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
iio: dummy: iio_simple_dummy: check the return value of kstrdup()
authorXiaoke Wang <xkernel.wang@foxmail.com>
Sat, 5 Mar 2022 03:14:05 +0000 (11:14 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 14 Jun 2022 16:41:33 +0000 (18:41 +0200)
commit87eea4319b2cc92ad9a6ff16c6f668a7e1f9b451
tree343de2fc61739d993f1d75ec3a76fda809316a2b
parent66f3a245bb5c93d710b2ce2e09b18ab176e99e8e
iio: dummy: iio_simple_dummy: check the return value of kstrdup()

[ Upstream commit ba93642188a6fed754bf7447f638bc410e05a929 ]

kstrdup() is also a memory allocation-related function, it returns NULL
when some memory errors happen. So it is better to check the return
value of it so to catch the memory error in time. Besides, there should
have a kfree() to clear up the allocation if we get a failure later in
this function to prevent memory leak.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
Link: https://lore.kernel.org/r/tencent_C920CFCC33B9CC1C63141FE1334A39FF8508@qq.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/iio/dummy/iio_simple_dummy.c