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=-12.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable 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 27C4EC433E2 for ; Mon, 14 Sep 2020 15:53:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD91C208DB for ; Mon, 14 Sep 2020 15:53:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="jiyzXlN+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726341AbgINPv4 (ORCPT ); Mon, 14 Sep 2020 11:51:56 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:48892 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726478AbgINPsD (ORCPT ); Mon, 14 Sep 2020 11:48:03 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 08EFinhd116673; Mon, 14 Sep 2020 15:47:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2020-01-29; bh=H2YIbikbT+ue7TZyoNfOVdVTmUKu3mXxNXJshc/z7uk=; b=jiyzXlN+4X0ouDKQx1IXJ9jeYsTdnxCuoLFG5wG1WwuJQ+yoRdsXaV353Is6lUY95f89 ufYvBTlrTxSMRxkH4gs5pOrF4CiRkoeUwwh7DdAmJHCNj530nQU62LLXgw7D5MH6LdkZ IDfvwE6BHu3x30npDrjD/k2S1cZtqK/Yqbxd4ttz3ArC+lx51jqe58CptGDJzvpl8MsC PsoKuTof6F0aazpotmzZhSD9PtW1SPL7H0OCOOOzsGhjfWfmOwSxUabWsrs0s90CBu9A 41hF3FEkJyztLWbCcaYbLs0LDPAuAdL4flXbqDg92HERYl4Kih1xNWRWOW94Z3t/ot5L rg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 33gp9kydm8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 14 Sep 2020 15:47:39 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 08EFjM1G176938; Mon, 14 Sep 2020 15:47:38 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 33h881tw2e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 14 Sep 2020 15:47:38 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 08EFla17011334; Mon, 14 Sep 2020 15:47:36 GMT Received: from kadam (/41.57.98.10) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 14 Sep 2020 15:47:35 +0000 Date: Mon, 14 Sep 2020 18:47:27 +0300 From: Dan Carpenter To: Andy Shevchenko Cc: kbuild@lists.01.org, Jie Deng , linux-i2c@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, lkp@intel.com, kbuild-all@lists.01.org, mst@redhat.com, jasowang@redhat.com, wsa+renesas@sang-engineering.com, wsa@kernel.org, jarkko.nikula@linux.intel.com, jdelvare@suse.de Subject: Re: [PATCH v2] i2c: virtio: add a virtio i2c frontend driver Message-ID: <20200914154726.GE18329@kadam> References: <20200914144807.GC4282@kadam> <20200914152455.GI3956970@smile.fi.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200914152455.GI3956970@smile.fi.intel.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9744 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 phishscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009140126 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9744 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 phishscore=0 spamscore=0 priorityscore=1501 suspectscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009140126 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. regards, dan carpenter > > # 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 > 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=-10.0 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,UNPARSEABLE_RELAY,URIBL_BLOCKED, USER_AGENT_SANE_1 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 162E9C43461 for ; Mon, 14 Sep 2020 15:47:49 +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 8BF2F208DB for ; Mon, 14 Sep 2020 15:47:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="jiyzXlN+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8BF2F208DB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.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 1EA8386769; Mon, 14 Sep 2020 15:47:48 +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 8azk8a+Dp2mf; Mon, 14 Sep 2020 15:47:46 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id DD67C86760; Mon, 14 Sep 2020 15:47:46 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id BFD20C088B; Mon, 14 Sep 2020 15:47:46 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 99D1FC0859 for ; Mon, 14 Sep 2020 15:47:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 8955586149 for ; Mon, 14 Sep 2020 15:47:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0umRY13jXFzV for ; Mon, 14 Sep 2020 15:47:44 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 5C36486130 for ; Mon, 14 Sep 2020 15:47:44 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 08EFinhd116673; Mon, 14 Sep 2020 15:47:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2020-01-29; bh=H2YIbikbT+ue7TZyoNfOVdVTmUKu3mXxNXJshc/z7uk=; b=jiyzXlN+4X0ouDKQx1IXJ9jeYsTdnxCuoLFG5wG1WwuJQ+yoRdsXaV353Is6lUY95f89 ufYvBTlrTxSMRxkH4gs5pOrF4CiRkoeUwwh7DdAmJHCNj530nQU62LLXgw7D5MH6LdkZ IDfvwE6BHu3x30npDrjD/k2S1cZtqK/Yqbxd4ttz3ArC+lx51jqe58CptGDJzvpl8MsC PsoKuTof6F0aazpotmzZhSD9PtW1SPL7H0OCOOOzsGhjfWfmOwSxUabWsrs0s90CBu9A 41hF3FEkJyztLWbCcaYbLs0LDPAuAdL4flXbqDg92HERYl4Kih1xNWRWOW94Z3t/ot5L rg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 33gp9kydm8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 14 Sep 2020 15:47:39 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 08EFjM1G176938; Mon, 14 Sep 2020 15:47:38 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 33h881tw2e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 14 Sep 2020 15:47:38 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 08EFla17011334; Mon, 14 Sep 2020 15:47:36 GMT Received: from kadam (/41.57.98.10) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 14 Sep 2020 15:47:35 +0000 Date: Mon, 14 Sep 2020 18:47:27 +0300 From: Dan Carpenter To: Andy Shevchenko Subject: Re: [PATCH v2] i2c: virtio: add a virtio i2c frontend driver Message-ID: <20200914154726.GE18329@kadam> References: <20200914144807.GC4282@kadam> <20200914152455.GI3956970@smile.fi.intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200914152455.GI3956970@smile.fi.intel.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9744 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 spamscore=0 adultscore=0 suspectscore=0 phishscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009140126 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9744 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 phishscore=0 spamscore=0 priorityscore=1501 suspectscore=0 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009140126 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: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. regards, dan carpenter > > # 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 > _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============5976430925277228849==" MIME-Version: 1.0 From: Dan Carpenter Subject: Re: [PATCH v2] i2c: virtio: add a virtio i2c frontend driver Date: Mon, 14 Sep 2020 18:47:27 +0300 Message-ID: <20200914154726.GE18329@kadam> In-Reply-To: <20200914152455.GI3956970@smile.fi.intel.com> List-Id: To: kbuild@lists.01.org --===============5976430925277228849== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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-ad= d-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 previou= sly assumed 'vmsg' could be null (see line 137) > > = > = > It's quite possible a false positive. Look at 122. But I agree that for-l= oop is > not the best for such things to understand. Perhaps switching to do {} wh= ile () > will make it better. > = Smatch is assuming that virtqueue_get_buf() can return NULL on the last iteration through the loop. regards, dan carpenter > > # https://github.com/0day-ci/linux/commit/0a54ec771966748fcbc86256b830b= 5f786168b7d = > > 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-f= rontend-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(str= uct 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 =3D i2c= _get_adapdata(adap); > > 0a54ec77196674 Jie Deng 2020-09-11 112 struct virtqueue *vq =3D 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 =3D 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 =3D &vi->vmsg; > > 0a54ec77196674 Jie Deng 2020-09-11 119 vmsg->buf =3D NULL; > > 0a54ec77196674 Jie Deng 2020-09-11 120 = > > 0a54ec77196674 Jie Deng 2020-09-11 121 for (i =3D 0; i < num; i++) { > > 0a54ec77196674 Jie Deng 2020-09-11 122 ret =3D virtio_i2c_add_msg(v= q, 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 =3D wait_for_compl= etion_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=3D0x%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 =3D (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 !=3D &vi->vmsg) { > > 0a54ec77196674 Jie Deng 2020-09-11 140 dev_err(&adap->dev, "msg[%= d]: addr=3D0x%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 !=3D VIRTI= O_I2C_MSG_OK) { > > 0a54ec77196674 Jie Deng 2020-09-11 145 dev_err(&adap->dev, "msg[%= d]: addr=3D0x%x error=3D%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 =3D 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->compl= etion); > > 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(a)lists.01.org = > = > = > = > -- = > With Best Regards, > Andy Shevchenko >=20 --===============5976430925277228849==-- From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============0386670799719528431==" MIME-Version: 1.0 From: Dan Carpenter To: kbuild-all@lists.01.org Subject: Re: [PATCH v2] i2c: virtio: add a virtio i2c frontend driver Date: Mon, 14 Sep 2020 18:47:27 +0300 Message-ID: <20200914154726.GE18329@kadam> In-Reply-To: <20200914152455.GI3956970@smile.fi.intel.com> List-Id: --===============0386670799719528431== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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-ad= d-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 previou= sly assumed 'vmsg' could be null (see line 137) > > = > = > It's quite possible a false positive. Look at 122. But I agree that for-l= oop is > not the best for such things to understand. Perhaps switching to do {} wh= ile () > will make it better. > = Smatch is assuming that virtqueue_get_buf() can return NULL on the last iteration through the loop. regards, dan carpenter > > # https://github.com/0day-ci/linux/commit/0a54ec771966748fcbc86256b830b= 5f786168b7d = > > 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-f= rontend-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(str= uct 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 =3D i2c= _get_adapdata(adap); > > 0a54ec77196674 Jie Deng 2020-09-11 112 struct virtqueue *vq =3D 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 =3D 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 =3D &vi->vmsg; > > 0a54ec77196674 Jie Deng 2020-09-11 119 vmsg->buf =3D NULL; > > 0a54ec77196674 Jie Deng 2020-09-11 120 = > > 0a54ec77196674 Jie Deng 2020-09-11 121 for (i =3D 0; i < num; i++) { > > 0a54ec77196674 Jie Deng 2020-09-11 122 ret =3D virtio_i2c_add_msg(v= q, 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 =3D wait_for_compl= etion_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=3D0x%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 =3D (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 !=3D &vi->vmsg) { > > 0a54ec77196674 Jie Deng 2020-09-11 140 dev_err(&adap->dev, "msg[%= d]: addr=3D0x%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 !=3D VIRTI= O_I2C_MSG_OK) { > > 0a54ec77196674 Jie Deng 2020-09-11 145 dev_err(&adap->dev, "msg[%= d]: addr=3D0x%x error=3D%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 =3D 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->compl= etion); > > 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(a)lists.01.org = > = > = > = > -- = > With Best Regards, > Andy Shevchenko >=20 --===============0386670799719528431==--