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 X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56D3EC433E2 for ; Mon, 14 Sep 2020 16:09:08 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E5CE620715 for ; Mon, 14 Sep 2020 16:09:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E5CE620715 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=virtualization-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 7B8C385D5C; Mon, 14 Sep 2020 16:09:07 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0PqwWZQ7Wyib; Mon, 14 Sep 2020 16:09:04 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 5125286841; Mon, 14 Sep 2020 16:08:55 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3EDD2C0859; Mon, 14 Sep 2020 16:08:55 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0ED8CC0051 for ; Mon, 14 Sep 2020 16:08:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id E62C32002E for ; Mon, 14 Sep 2020 16:08:53 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aOK242-v-Mwo for ; Mon, 14 Sep 2020 16:08:51 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by silver.osuosl.org (Postfix) with ESMTPS id B20C61FDFB for ; Mon, 14 Sep 2020 16:08:51 +0000 (UTC) IronPort-SDR: JDp4Mhs6WUCkKRKmeBlo5xtH3YMqKC2WbbdkpPiFsph1N/pdBr3UL6nxPyZ2PxsCkwIRrqBuZi Gmp9keMnmOzQ== X-IronPort-AV: E=McAfee;i="6000,8403,9744"; a="146792576" X-IronPort-AV: E=Sophos;i="5.76,426,1592895600"; d="scan'208";a="146792576" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Sep 2020 09:08:50 -0700 IronPort-SDR: UiGrMlA3ZvzCKetd+zbQl9xfL2hz20+ZIEgqGOqpEgt+1xUQn95d6KsEA4pHndFmAv+wFTEFaD yMyLQNempZNA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,426,1592895600"; d="scan'208";a="335328062" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga008.jf.intel.com with ESMTP; 14 Sep 2020 09:08:46 -0700 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1kHr23-00GdbG-9I; Mon, 14 Sep 2020 19:08:43 +0300 Date: Mon, 14 Sep 2020 19:08:43 +0300 From: Andy Shevchenko To: Dan Carpenter Subject: Re: [PATCH v2] i2c: virtio: add a virtio i2c frontend driver Message-ID: <20200914160843.GM3956970@smile.fi.intel.com> References: <20200914144807.GC4282@kadam> <20200914152455.GI3956970@smile.fi.intel.com> <20200914154726.GE18329@kadam> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200914154726.GE18329@kadam> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Cc: kbuild-all@lists.01.org, lkp@intel.com, mst@redhat.com, kbuild@lists.01.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, wsa@kernel.org, wsa+renesas@sang-engineering.com, jarkko.nikula@linux.intel.com, linux-i2c@vger.kernel.org, jdelvare@suse.de X-BeenThere: virtualization@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux virtualization List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" On Mon, Sep 14, 2020 at 06:47:27PM +0300, Dan Carpenter wrote: > On Mon, Sep 14, 2020 at 06:24:55PM +0300, Andy Shevchenko wrote: > > On Mon, Sep 14, 2020 at 05:48:07PM +0300, Dan Carpenter wrote: > > > Hi Jie, > > > > > > url: https://github.com/0day-ci/linux/commits/Jie-Deng/i2c-virtio-add-a-virtio-i2c-frontend-driver/20200911-115013 > > > base: https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/for-next > > > config: parisc-randconfig-m031-20200913 (attached as .config) > > > compiler: hppa-linux-gcc (GCC) 9.3.0 > > > > > > If you fix the issue, kindly add following tag as appropriate > > > Reported-by: kernel test robot > > > Reported-by: Dan Carpenter > > > > > > smatch warnings: > > > drivers/i2c/busses/i2c-virtio.c:160 virtio_i2c_xfer() error: we previously assumed 'vmsg' could be null (see line 137) > > > > > > > It's quite possible a false positive. Look at 122. But I agree that for-loop is > > not the best for such things to understand. Perhaps switching to do {} while () > > will make it better. > > > > Smatch is assuming that virtqueue_get_buf() can return NULL on the last > iteration through the loop. I see now. Thanks. > > > # https://github.com/0day-ci/linux/commit/0a54ec771966748fcbc86256b830b5f786168b7d > > > git remote add linux-review https://github.com/0day-ci/linux > > > git fetch --no-tags linux-review Jie-Deng/i2c-virtio-add-a-virtio-i2c-frontend-driver/20200911-115013 > > > git checkout 0a54ec771966748fcbc86256b830b5f786168b7d > > > vim +/vmsg +160 drivers/i2c/busses/i2c-virtio.c > > > > > > 0a54ec77196674 Jie Deng 2020-09-11 109 static int virtio_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) > > > 0a54ec77196674 Jie Deng 2020-09-11 110 { > > > 0a54ec77196674 Jie Deng 2020-09-11 111 struct virtio_i2c *vi = i2c_get_adapdata(adap); > > > 0a54ec77196674 Jie Deng 2020-09-11 112 struct virtqueue *vq = vi->vq; > > > 0a54ec77196674 Jie Deng 2020-09-11 113 struct virtio_i2c_msg *vmsg; > > > 0a54ec77196674 Jie Deng 2020-09-11 114 unsigned long time_left; > > > 0a54ec77196674 Jie Deng 2020-09-11 115 int len, i, ret = 0; > > > 0a54ec77196674 Jie Deng 2020-09-11 116 > > > 0a54ec77196674 Jie Deng 2020-09-11 117 mutex_lock(&vi->i2c_lock); > > > 0a54ec77196674 Jie Deng 2020-09-11 118 vmsg = &vi->vmsg; > > > 0a54ec77196674 Jie Deng 2020-09-11 119 vmsg->buf = NULL; > > > 0a54ec77196674 Jie Deng 2020-09-11 120 > > > 0a54ec77196674 Jie Deng 2020-09-11 121 for (i = 0; i < num; i++) { > > > 0a54ec77196674 Jie Deng 2020-09-11 122 ret = virtio_i2c_add_msg(vq, vmsg, &msgs[i]); > > > 0a54ec77196674 Jie Deng 2020-09-11 123 if (ret) { > > > 0a54ec77196674 Jie Deng 2020-09-11 124 dev_err(&adap->dev, "failed to add msg[%d] to virtqueue.\n", i); > > > 0a54ec77196674 Jie Deng 2020-09-11 125 break; > > > 0a54ec77196674 Jie Deng 2020-09-11 126 } > > > 0a54ec77196674 Jie Deng 2020-09-11 127 > > > 0a54ec77196674 Jie Deng 2020-09-11 128 virtqueue_kick(vq); > > > 0a54ec77196674 Jie Deng 2020-09-11 129 > > > 0a54ec77196674 Jie Deng 2020-09-11 130 time_left = wait_for_completion_timeout(&vi->completion, adap->timeout); > > > 0a54ec77196674 Jie Deng 2020-09-11 131 if (!time_left) { > > > 0a54ec77196674 Jie Deng 2020-09-11 132 dev_err(&adap->dev, "msg[%d]: addr=0x%x timeout.\n", i, msgs[i].addr); > > > 0a54ec77196674 Jie Deng 2020-09-11 133 break; > > > 0a54ec77196674 Jie Deng 2020-09-11 134 } > > > 0a54ec77196674 Jie Deng 2020-09-11 135 > > > 0a54ec77196674 Jie Deng 2020-09-11 136 vmsg = (struct virtio_i2c_msg *)virtqueue_get_buf(vq, &len); > > > 0a54ec77196674 Jie Deng 2020-09-11 @137 if (vmsg) { > > > ^^^^ > > > Check for NULL. > > > > > > 0a54ec77196674 Jie Deng 2020-09-11 138 /* vmsg should point to the same address with &vi->vmsg */ > > > 0a54ec77196674 Jie Deng 2020-09-11 139 if (vmsg != &vi->vmsg) { > > > 0a54ec77196674 Jie Deng 2020-09-11 140 dev_err(&adap->dev, "msg[%d]: addr=0x%x virtqueue error.\n", > > > 0a54ec77196674 Jie Deng 2020-09-11 141 i, le16_to_cpu(vmsg->hdr.addr)); > > > 0a54ec77196674 Jie Deng 2020-09-11 142 break; > > > 0a54ec77196674 Jie Deng 2020-09-11 143 } > > > 0a54ec77196674 Jie Deng 2020-09-11 144 if (vmsg->status != VIRTIO_I2C_MSG_OK) { > > > 0a54ec77196674 Jie Deng 2020-09-11 145 dev_err(&adap->dev, "msg[%d]: addr=0x%x error=%d.\n", > > > 0a54ec77196674 Jie Deng 2020-09-11 146 i, le16_to_cpu(vmsg->hdr.addr), vmsg->status); > > > 0a54ec77196674 Jie Deng 2020-09-11 147 break; > > > 0a54ec77196674 Jie Deng 2020-09-11 148 } > > > 0a54ec77196674 Jie Deng 2020-09-11 149 if ((msgs[i].flags & I2C_M_RD) && msgs[i].len) > > > 0a54ec77196674 Jie Deng 2020-09-11 150 memcpy(msgs[i].buf, vmsg->buf, msgs[i].len); > > > 0a54ec77196674 Jie Deng 2020-09-11 151 > > > 0a54ec77196674 Jie Deng 2020-09-11 152 kfree(vmsg->buf); > > > 0a54ec77196674 Jie Deng 2020-09-11 153 vmsg->buf = NULL; > > > 0a54ec77196674 Jie Deng 2020-09-11 154 } > > > 0a54ec77196674 Jie Deng 2020-09-11 155 > > > 0a54ec77196674 Jie Deng 2020-09-11 156 reinit_completion(&vi->completion); > > > 0a54ec77196674 Jie Deng 2020-09-11 157 } > > > 0a54ec77196674 Jie Deng 2020-09-11 158 > > > 0a54ec77196674 Jie Deng 2020-09-11 159 mutex_unlock(&vi->i2c_lock); > > > 0a54ec77196674 Jie Deng 2020-09-11 @160 kfree(vmsg->buf); > > > ^^^^^^^^^ > > > Unchecked dereference. > > > > > > 0a54ec77196674 Jie Deng 2020-09-11 161 return ((ret < 0) ? ret : i); > > > 0a54ec77196674 Jie Deng 2020-09-11 162 } > > > > > > --- > > > 0-DAY CI Kernel Test Service, Intel Corporation > > > https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org > > > > > > > > -- > > With Best Regards, > > Andy Shevchenko > > -- With Best Regards, Andy Shevchenko _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization