tools/iio: Add memory allocation failure check for trigger_name

[ Upstream commit 3c6b818b097dd6932859bcc3d6722a74ec5931c1 ]

Added a check to handle memory allocation failure for `trigger_name`
and return `-ENOMEM`.

Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
Link: https://patch.msgid.link/20240828093129.3040-1-zhujun2@cmss.chinamobile.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Zhu Jun 2024-08-28 02:31:29 -07:00 committed by Greg Kroah-Hartman
parent b01793cc63
commit 5b53a7a6bd
1 changed files with 4 additions and 0 deletions

View File

@ -498,6 +498,10 @@ int main(int argc, char **argv)
return -ENOMEM; return -ENOMEM;
} }
trigger_name = malloc(IIO_MAX_NAME_LENGTH); trigger_name = malloc(IIO_MAX_NAME_LENGTH);
if (!trigger_name) {
ret = -ENOMEM;
goto error;
}
ret = read_sysfs_string("name", trig_dev_name, trigger_name); ret = read_sysfs_string("name", trig_dev_name, trigger_name);
free(trig_dev_name); free(trig_dev_name);
if (ret < 0) { if (ret < 0) {