From patchwork Thu Jan 26 15:36:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harshit Mogalapalli X-Patchwork-Id: 48770 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp341410wrn; Thu, 26 Jan 2023 07:50:16 -0800 (PST) X-Google-Smtp-Source: AMrXdXvqtEvgKO0OFDzI1uJY+OzHc6c2Uif5C6sFPZNbo3596HVKva/DPFSdjVuD71n/Y9k3qXtM X-Received: by 2002:a05:6402:35c1:b0:49b:52b3:cae6 with SMTP id z1-20020a05640235c100b0049b52b3cae6mr50557155edc.30.1674748216526; Thu, 26 Jan 2023 07:50:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674748216; cv=none; d=google.com; s=arc-20160816; b=03dZIfok1/K/9zVyCpj2vZmiu+lmib/A8os3exDCIqzoA2e0jrwNJa+2PdIagjUoHA A9KMh1Rlk9vOvUjSWeUAf1JnyVKbuqwOUcyLiF0MQJ56TNp2mkXK03cM+PrZHqbXNLna w+pTVvMW10HRBuyMqLGyhMNzQE21rIrafWfX3sfQzcJ7lE2NvLOeTgs1XbJGDb7CJDnS ov+S9AvzaYenOLw+2zway4QX+oQVyC2TpScoDBuLDOAnVE6mjKvpty1fFJ9CgkEiPT8Z L5Z2X693RGPPpnB22+xe0GJb8db1HBzF0e8v2yqi88NUQmgpC2DtAVsPQIO1RTkGkbIj QH3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=RSyPL1U6GXPs6hPxIDi4w+LX+f9ekl+CEHIFrSXE6WI=; b=G4AecLmtxACENjozKGnZ8SEcIL2WeLQqv3Xb8O4rfhHQeZW8+mEyIdgRwv2ng23rMN KqfNi3YGSBrjRmc5lT18sjL9AO4n6WA2Bzqw5LuquZsXuYP9Aow35xqJz3qiIymqO/XY p/g6+SFPVb9Gz4ONDaWrwsP8CrSMxnMY/iK/iAbPuYckC1dKNzoFZGkX6MgFFeivRgkd WXgC3w1/21fQGP59Qgf+zE7ZpZDXVR5Z2yQxlGEKebKb6sRDIunVWF3EGbyOCsPqSrBq InbS4kQMctt+BEEfev9sFFFMK2XFEy3X9LU+M1FUzlYOW4Fyb1blg+zWr4wyhZ7cg3yV pI/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@oracle.com header.s=corp-2022-7-12 header.b=GGkLrhfX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n8-20020aa7d048000000b004a089b0b8ecsi1796993edo.516.2023.01.26.07.49.52; Thu, 26 Jan 2023 07:50:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@oracle.com header.s=corp-2022-7-12 header.b=GGkLrhfX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230271AbjAZPgm (ORCPT + 99 others); Thu, 26 Jan 2023 10:36:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229674AbjAZPgl (ORCPT ); Thu, 26 Jan 2023 10:36:41 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89CCAEC47; Thu, 26 Jan 2023 07:36:40 -0800 (PST) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30QEjHqJ007113; Thu, 26 Jan 2023 15:36:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=corp-2022-7-12; bh=RSyPL1U6GXPs6hPxIDi4w+LX+f9ekl+CEHIFrSXE6WI=; b=GGkLrhfXbAWWTAjcyTvidaSUGcC7KoyI9pAHYg4oAKnwVB7hLlOYFKFXQjB5IBkbM2um GpoIfZ3X4E8hUBsXLuwjiIKkht6lcHGVTr/tK5vnpGydC8O9c1u2mxnPRdRFpzsgMO47 pXMxL09TZMX/0YaGgUh2/I/FZxxDGUnRfSYFDm3kDYWBCdEkio3wkQBlZRgVuc8sfkmD C8xe9u06W8J5wHzVoV8+XU3dTLIYZmKWVAcc+5UiupaNOzxfZg0vCkHNoTvLpp9/chfc FUNhLbSNZ7cLcnLcsFxL1WaqOK3/NOLzc0u40xPfpuO+hUyzoyKcgwihFEwfu99sXxGo qg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3n86ybjj34-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Jan 2023 15:36:23 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 30QEvf8o019163; Thu, 26 Jan 2023 15:36:22 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3n86gebrbk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Jan 2023 15:36:22 +0000 Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 30QFUTSf014868; Thu, 26 Jan 2023 15:36:21 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3n86gebrap-1; Thu, 26 Jan 2023 15:36:21 +0000 From: Harshit Mogalapalli Cc: harshit.m.mogalapalli@oracle.com, error27@gmail.com, Jonathan Cameron , Lars-Peter Clausen , Irina Tirdea , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] iio: accel: mma9551_core: Prevent uninitialized variable in mma9551_read_config_word() Date: Thu, 26 Jan 2023 07:36:09 -0800 Message-Id: <20230126153610.3586243-1-harshit.m.mogalapalli@oracle.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-26_07,2023-01-26_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 suspectscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301260151 X-Proofpoint-GUID: KrAAVUjle3Hq6Fo8EIgcTLaOqSLmDv81 X-Proofpoint-ORIG-GUID: KrAAVUjle3Hq6Fo8EIgcTLaOqSLmDv81 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756100785903332771?= X-GMAIL-MSGID: =?utf-8?q?1756100785903332771?= Smatch Warns: drivers/iio/accel/mma9551_core.c:299 mma9551_read_config_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. Fixes: 40cb761306d6 ("iio: add driver for Freescale MMA9553") Signed-off-by: Harshit Mogalapalli --- This is detected using static analysis. --- 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 64ca7d7a9673..75eee7f7303a 100644 --- a/drivers/iio/accel/mma9551_core.c +++ b/drivers/iio/accel/mma9551_core.c @@ -296,9 +296,12 @@ int mma9551_read_config_word(struct i2c_client *client, u8 app_id, ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_CONFIG, reg, NULL, 0, (u8 *)&v, 2); + if (ret < 0) + return ret; + *val = be16_to_cpu(v); - return ret; + return 0; } EXPORT_SYMBOL_NS(mma9551_read_config_word, IIO_MMA9551);