Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6971684rwr; Wed, 10 May 2023 01:52:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7TW1w+ZYf4lkfYYY0c8mfO1Y/amQ9l/AMLRuRakJyAylQcpk7iNA/ob7hoyMW9+Btu/NMX X-Received: by 2002:a05:6a20:7490:b0:e4:b52:76c9 with SMTP id p16-20020a056a20749000b000e40b5276c9mr20602286pzd.23.1683708745319; Wed, 10 May 2023 01:52:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683708745; cv=none; d=google.com; s=arc-20160816; b=hQFKTqOcmgtqhNpvr0RbDo3K+F9rEGgH43Tx2YpJNLEaKxm3hkJN6w2eyGY9dI2x5Y vdD+iu2XQlDiELHW45khQXgQXRoRBnhR6ERzDbnPWFeCOP8IKUVyXfe0PWAoJYp3z+i4 2+0IvKdEiW21Hh+JNthP3LJpR+hNpviw0KwUVsZq3p93XUFmK3nro+rTN+HiXhPzCXAp d0AZ8/+/0LDNLVEYgMho7vYZKv0JINwl77+UWNgm1GQGrthortJJEI9gI/Z7yxyhYeGY heohAqc4sUqEq85oPLT2jdvHHUiR2jUY8Cq1esRI0qfpZO8gINnQKky+zT4sQ8MA9tg6 Zbhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=URGhCQs1rl6awSzpzIAKRNceZT9h15+rICvuMhdIDz8=; b=tBQ5f20AOlpj45ZbncrnSHfX0i6KqVBK/4vJWGgV/Y4j2ZfIRSSPhGx7YWA4fAoZH6 vrBx2EPwxDyBBIn6z8gFuOImofEr1I4/eXnfXKBjb7JBtwcLqahlDq9SoRiEGp0u95gQ 4p8ES1+WaCzVPYzjCka4ldVtF0c8bw25XwV5IJIf7J5FxlJT5t/BQdaMRlx4Q/lKS4ai Ofgk0vXPCKCNDv2l9jTQ6KvnfREHSs8m9TRl4yuEbS4NHVL3vZDH78lX36Cnh+tJ1Gd1 F8V7aHCret76EGFMzPSzpA8BHT/Hh/F+YqqtBD3RSZnBb7FHQPCLkiPpiT4VvAW520wb eCow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@126.com header.s=s110527 header.b="H/FclKem"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=126.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q200-20020a632ad1000000b0052ca7192669si3710688pgq.657.2023.05.10.01.52.11; Wed, 10 May 2023 01:52:25 -0700 (PDT) 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=pass header.i=@126.com header.s=s110527 header.b="H/FclKem"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=126.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236523AbjEJImg (ORCPT + 99 others); Wed, 10 May 2023 04:42:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236751AbjEJIm1 (ORCPT ); Wed, 10 May 2023 04:42:27 -0400 Received: from m126.mail.126.com (m126.mail.126.com [220.181.12.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 82AFC7EF7; Wed, 10 May 2023 01:42:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=URGhC Qs1rl6awSzpzIAKRNceZT9h15+rICvuMhdIDz8=; b=H/FclKemSkmFcCKcd/azD 1DDzqwlCFocj9qu6yKeAGIx+OKTFJANjWMEVtLzVHdzM2Ec9+FmUkwFl8IpGkv+h uCwphwjB7uiMUNKfEKaWdMvg7DffmvtTMSce+b+rOr2MsKN17eE1kEdbtesvrtON 4nciLFozwk682eb3U66teg= Received: from king.lan (unknown [103.163.180.46]) by zwqz-smtp-mta-g3-0 (Coremail) with SMTP id _____wC39HCdWFtkpdYvAg--.4572S2; Wed, 10 May 2023 16:41:01 +0800 (CST) From: wangyouwan@126.com To: jarkko.nikula@linux.intel.com, andriy.shevchenko@linux.intel.com, mika.westerberg@linux.intel.com, jsd@semihalf.com Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, youwan Wang Subject: [PATCH] i2c: fix crash with msgs is NULL points Date: Wed, 10 May 2023 16:40:57 +0800 Message-Id: <20230510084057.17313-1-wangyouwan@126.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wC39HCdWFtkpdYvAg--.4572S2 X-Coremail-Antispam: 1Uf129KBjvdXoWruw1fKF48WrW5WryDZFWDArb_yoWDCFbE9r n7Za92grW2yan3Gw13AFsxXrZ09r18Wa4xuF1xt393Cr1jyr1kAF4DAry3Zr1DXF47KFZ0 g3Wq9F1rAr43JjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUjUPEPUUUUU== X-Originating-IP: [103.163.180.46] X-CM-SenderInfo: 5zdqw5prxzt0a6rslhhfrp/1tbi3B9rFVpEFVGPZQAAsN X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: youwan Wang There is some probability that msgs is empty Signed-off-by: youwan Wang --- drivers/i2c/busses/i2c-designware-master.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c index 55ea91a63382..e11a73fd0a41 100644 --- a/drivers/i2c/busses/i2c-designware-master.c +++ b/drivers/i2c/busses/i2c-designware-master.c @@ -366,12 +366,17 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev) struct i2c_msg *msgs = dev->msgs; u32 intr_mask; int tx_limit, rx_limit; - u32 addr = msgs[dev->msg_write_idx].addr; + u32 addr; u32 buf_len = dev->tx_buf_len; u8 *buf = dev->tx_buf; bool need_restart = false; unsigned int flr; + if (WARN_ON(!msgs)) + return; + + addr = msgs[dev->msg_write_idx].addr; + intr_mask = DW_IC_INTR_MASTER_MASK; for (; dev->msg_write_idx < dev->msgs_num; dev->msg_write_idx++) { -- 2.25.1