From nobody Sat Nov 30 03:36:37 2024 Received: from cmccmta2.chinamobile.com (cmccmta2.chinamobile.com [111.22.67.135]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C69B13A40F; Thu, 12 Sep 2024 03:28:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=111.22.67.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726111741; cv=none; b=INuunB5kFWnJyPz5ifqvtuQArO8kpYmF8CVVVv0lWIk63uKDJKWOfVY4u2Lq8a7+LUCEZfQXKIdvXfGZsLezzqo+3TDDrmBGSJkQ/GzWeV5QcCQflga6mDIMYS0NssIuc07+Ejce78i7zPVJDxOiywytaZPedbmJ3Hn+eQJeiT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726111741; c=relaxed/simple; bh=aaHump5Ez603AvINyLLmEIe2gGnCkcovisCUNr6gNsk=; h=From:To:Cc:Subject:Date:Message-Id; b=Csc/ErgKAvugASvJhjMkBKJtZr2xPRCkMEOJOUq30q+ueHiwsddsYD6012IbLuXTzPwHWmslE8lo1cg86DTFM7fg3UEv/lBIDBC60riltV6fMe5Hv/icbhI8p4gw/KNfe5DLHPigXMZLGf/QtJfObGL1TShcMVTB2bA7bZzNyh8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cmss.chinamobile.com; spf=pass smtp.mailfrom=cmss.chinamobile.com; arc=none smtp.client-ip=111.22.67.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cmss.chinamobile.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmss.chinamobile.com X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from spf.mail.chinamobile.com (unknown[10.188.0.87]) by rmmx-syy-dmz-app07-12007 (RichMail) with SMTP id 2ee766e25ff86b5-246bb; Thu, 12 Sep 2024 11:28:56 +0800 (CST) X-RM-TRANSID: 2ee766e25ff86b5-246bb X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from ubuntu.localdomain (unknown[10.54.5.255]) by rmsmtp-syy-appsvr02-12002 (RichMail) with SMTP id 2ee266e25ff7691-050ca; Thu, 12 Sep 2024 11:28:56 +0800 (CST) X-RM-TRANSID: 2ee266e25ff7691-050ca From: Zhu Jun To: jic23@kernel.org Cc: lars@metafoo.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, zhujun2@cmss.chinamobile.com Subject: [RESEND] tools/iio: Add memory allocation failure check for trigger_name Date: Wed, 11 Sep 2024 20:28:54 -0700 Message-Id: <20240912032854.3008-1-zhujun2@cmss.chinamobile.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Added a check to handle memory allocation failure for `trigger_name` and return `-ENOMEM`. Signed-off-by: Zhu Jun --- 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 =3D malloc(IIO_MAX_NAME_LENGTH); + if (!trigger_name) { + ret =3D -ENOMEM; + goto error; + } ret =3D read_sysfs_string("name", trig_dev_name, trigger_name); free(trig_dev_name); if (ret < 0) { --=20 2.17.1