[RESEND] tools/iio: Add memory allocation failure check for trigger_name

Zhu Jun posted 1 patch 2 months, 2 weeks ago
There is a newer version of this series
tools/iio/iio_generic_buffer.c | 4 ++++
1 file changed, 4 insertions(+)
[RESEND] tools/iio: Add memory allocation failure check for trigger_name
Posted by Zhu Jun 2 months, 2 weeks ago
Added a check to handle memory allocation failure for `trigger_name`
and return `-ENOMEM`.

Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
 tools/iio/iio_generic_buffer.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/iio/iio_generic_buffer.c b/tools/iio/iio_generic_buffer.c
index 0d0a7a19d6f9..9ef5ee087eda 100644
--- a/tools/iio/iio_generic_buffer.c
+++ b/tools/iio/iio_generic_buffer.c
@@ -498,6 +498,10 @@ int main(int argc, char **argv)
 			return -ENOMEM;
 		}
 		trigger_name = malloc(IIO_MAX_NAME_LENGTH);
+		if (!trigger_name) {
+			ret = -ENOMEM;
+			goto error;
+		}
 		ret = read_sysfs_string("name", trig_dev_name, trigger_name);
 		free(trig_dev_name);
 		if (ret < 0) {
-- 
2.17.1
Re: [RESEND] tools/iio: Add memory allocation failure check for trigger_name
Posted by Jonathan Cameron 2 months, 2 weeks ago
On Wed, 11 Sep 2024 20:28:46 -0700
Zhu Jun <zhujun2@cmss.chinamobile.com> wrote:

> Added a check to handle memory allocation failure for `trigger_name`
> and return `-ENOMEM`.
> 
> Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
I queued this up already but seems I forgot to say so!

Sorry about that. It is on my testing branch until I can rebase on rc1
when that becomes available.

Thanks,

Jonathan

> ---
>  tools/iio/iio_generic_buffer.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/iio/iio_generic_buffer.c b/tools/iio/iio_generic_buffer.c
> index 0d0a7a19d6f9..9ef5ee087eda 100644
> --- a/tools/iio/iio_generic_buffer.c
> +++ b/tools/iio/iio_generic_buffer.c
> @@ -498,6 +498,10 @@ int main(int argc, char **argv)
>  			return -ENOMEM;
>  		}
>  		trigger_name = malloc(IIO_MAX_NAME_LENGTH);
> +		if (!trigger_name) {
> +			ret = -ENOMEM;
> +			goto error;
> +		}
>  		ret = read_sysfs_string("name", trig_dev_name, trigger_name);
>  		free(trig_dev_name);
>  		if (ret < 0) {