From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA623C7EE33 for ; Fri, 3 Mar 2023 21:51:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232908AbjCCVvs (ORCPT ); Fri, 3 Mar 2023 16:51:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233382AbjCCVvO (ORCPT ); Fri, 3 Mar 2023 16:51:14 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1314964214; Fri, 3 Mar 2023 13:47:14 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 321B0B819DC; Fri, 3 Mar 2023 21:46:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EAD7C4339C; Fri, 3 Mar 2023 21:46:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677879964; bh=awSGxbBJbNwqQAGMSrILvpViFoA4EgDdJh89yVRtIHM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FcL7q3yFSMIf3xMm176HeQ5NKvQqAvreJN416XtTckKPg1PbmrTKQWDSAVLNo1KT1 TgJlHyWKTgAcCC+8BU3pBN4DdE+6rrWUdi+qaNBwWw4jW/RIAdDqIci9I3L1LZnJkm kGhNWpCJzVRnpQ2BRX2tKARrjv6aY55fJpqHSa/SXdtTuQRB1RSd8u4gvqVLcFq7YB MS3fnXLaY9ekeu/aZSbH2JllvPDcEFe/ZXdS/Ct3UzfgwD2Zw7oTNjehMVY4SGtgV6 Fj4dmsOUHDReHlIm3jKflmPTlVBLxNsK1uF0kb+qUIxXpZfHTL8C0OrfufGAdjtrH0 LuUbG86eYynXg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Harshit Mogalapalli , Jonathan Cameron , Sasha Levin , jic23@kernel.org, linux-iio@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 16/50] iio: accel: mma9551_core: Prevent uninitialized variable in mma9551_read_status_word() Date: Fri, 3 Mar 2023 16:44:57 -0500 Message-Id: <20230303214531.1450154-16-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230303214531.1450154-1-sashal@kernel.org> References: <20230303214531.1450154-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Harshit Mogalapalli [ Upstream commit e56d2c34ce9dc122b1a618172ec0e05e50adb9e9 ] Smatch Warns: drivers/iio/accel/mma9551_core.c:357 mma9551_read_status_word() error: uninitialized symbol 'v'. When (offset >= 1 << 12) is true mma9551_transfer() will return -EINVAL without 'v' being initialized, so check for the error and return. Note: Not a bug as such because the caller checks return value and doesn't not use this parameter in the problem case. Signed-off-by: Harshit Mogalapalli Link: https://lore.kernel.org/r/20230126152147.3585874-1-harshit.m.mogalapalli@oracle.com Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- drivers/iio/accel/mma9551_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/iio/accel/mma9551_core.c b/drivers/iio/accel/mma9551_core.c index fbf2e2c45678b..413610a749c24 100644 --- a/drivers/iio/accel/mma9551_core.c +++ b/drivers/iio/accel/mma9551_core.c @@ -354,9 +354,12 @@ int mma9551_read_status_word(struct i2c_client *client, u8 app_id, ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_STATUS, reg, NULL, 0, (u8 *)&v, 2); + if (ret < 0) + return ret; + *val = be16_to_cpu(v); - return ret; + return 0; } EXPORT_SYMBOL(mma9551_read_status_word); -- 2.39.2