Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp1270529pxa; Fri, 28 Aug 2020 08:14:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZVD3JKAgdKNtdAJvOduHhtajvFPrbFdLEsYCrNeWbjKFguftm8A5hu32HFmjCHdE5emfn X-Received: by 2002:a17:906:4882:: with SMTP id v2mr2305202ejq.302.1598627658174; Fri, 28 Aug 2020 08:14:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598627658; cv=none; d=google.com; s=arc-20160816; b=tIvC6FUiPM63JIw8cfZ7zSPpuUi1OZWM/PIGFncFfvXjn5NusN1nIQ7EM2VbNswvZx Ou36hGkNu6WCalfPJqTf17hzgxNmJGMW1uNeHVgkPHnUbRn7Bd+iZPJLLA14QL6ddeJ8 3feMtQjuVkatcrZwbIprOL/xwEEdakYT8Htysh9EhFmdQwYhX6SyPvmAxJUTewZtfe7S nXQe/DxaqQqXt8DeXZf+mXPjy57hL/vdQTKt9W5XE3d3TOMYa1wWW3yi0AEcD/e/5t5B BBViFD7i3fJwi/jU1qTv1h0Qdt/AT4+kW+iqA7La80HJvLOlFQ55IVXsamglkZQgLnJO 04hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=BKjrrvGukms7oApav7erWoo0oPTGMcbx8gjhXd3ukgs=; b=wsXvhcnSlqZvi+q5qntKb06etWFMTJNZU+Q7JuFsqXPogRSmYCwutplmLJ4Ca9b/dn oC8PeTmkwbzNupGHSW6HuuweE3Hz9FglXvFRbPx+kXjrBiWBuSy6TWa+oGiIr6jDXl0+ hMDc18Ev8TTJgtHpt69gvTNq6E9xxzieHwCzGvAYvmL9U7vN2jKZ9RyWw7JZLYMPM0j+ wOhx/3L+PbmfpbE0WfAXWHAcP/eX0xQ5lOnsQszLGFLQ+IbROIMGpSikhpPcEg24RkXQ XMfPVixEJR8C+04NPfHytb40RptrX6NkKTDAdmfN4v6YcQmZszRr/vYrCOJkkUePFMdb FdVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NhhM7Wd+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d10si794847edh.341.2020.08.28.08.13.55; Fri, 28 Aug 2020 08:14:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NhhM7Wd+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728210AbgH1PNV (ORCPT + 99 others); Fri, 28 Aug 2020 11:13:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726579AbgH1PNO (ORCPT ); Fri, 28 Aug 2020 11:13:14 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF48FC06121B for ; Fri, 28 Aug 2020 08:13:13 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id p11so795855pfn.11 for ; Fri, 28 Aug 2020 08:13:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BKjrrvGukms7oApav7erWoo0oPTGMcbx8gjhXd3ukgs=; b=NhhM7Wd+6AXFxeOeMWRB148tGgNlOMcALtzVTyDpKSNCuzc3VWYLfJz/pX5kXgMHGL 9yWWnDA5z/smkM1Md/N/OArnjuz3dkLQV4msTL+jLALnqY9rkSCrrIw3nio1scj68TCz kmbApPm0zBAt0F7neVf0zLYRSsyNM0OCcLf+HpLOhoJcFqOK+xSHUgVdylKhSuEnIixE rpId1DnDwsD41p0iGXpblh/s1NjnVMFJ/HXYO3mQuwurIrfBJTzxcGKgRyueLjGR9ZhD r9pYDJDfQwYo++eOmCF7TQpboaZRr/hNx95K1YSvRQpGo5gRDwPlVae/L9cg29T3IQBh 8lag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BKjrrvGukms7oApav7erWoo0oPTGMcbx8gjhXd3ukgs=; b=cNMAubD3rU5vNVar0rv3qVoEIwruNiZTM6bvB5WeUgpeFlclDkOyuLl4EwBYsM6G5m ZckdLM9PNwHDw7+0zrGGDm5dVPrQxX/B1A8uPENL/aibMapHnnrkVvRdi2gPsGl2IsMg pYuTCsfVpjSjxPLLNjPLVenuDS3m3XHQy05HVga1JhP4T/AmX1JRcRjVAu/zZrzHXWTx WalZMNK1k//B+lsQzVC3W+3MNVMcXo+pJrQjZxIEekqRYFB86aponRSuwoh+p2M61ITD ElrJmZSsK8h/wWKmRGyA39j2979b3PBD9Fb5XCIJgMoiEgPlbIQO0zmqpzWg5UCy4PkG YM8w== X-Gm-Message-State: AOAM5320ldwcCEctz9uvfcItzx5LaPVHGXWKFCN8UODT505NM/8bR2of JWtfToDwiXrTpX5LIsVT7cuLOSmwu3gsPjl86q/MJQ== X-Received: by 2002:a62:1514:: with SMTP id 20mr1712792pfv.62.1598627593154; Fri, 28 Aug 2020 08:13:13 -0700 (PDT) MIME-Version: 1.0 References: <20200828145518.26324-1-trix@redhat.com> In-Reply-To: <20200828145518.26324-1-trix@redhat.com> From: Nick Desaulniers Date: Fri, 28 Aug 2020 08:13:02 -0700 Message-ID: Subject: Re: [PATCH] media: ov7670: check status of ov7670_read To: trix@redhat.com Cc: Jonathan Corbet , Mauro Carvalho Chehab , Nathan Chancellor , linux-media@vger.kernel.org, LKML , Masahiro Yamada , Nathan Huckleberry Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 28, 2020 at 7:55 AM wrote: > > From: Tom Rix > > clang static analysis flags this representative problem > > drivers/media/i2c/ov7670.c:1463:9: warning: Assigned > value is garbage or undefined > *value = gain; > ^ ~~~~ > > gain is set by a successful call to ov7670_read() Indeed, it looks like gain is only valid if the return value from ov7670_read() is >= 0. Would it be simpler to just initialize gain to 0 in ov7670_g_gain? Side question; I'm super happy to see someone sending patches for things identified by clang's static analyzer. I'm curious, Tom, how did you run it? Did you use the recently landed in kbuild-next support for the make target `make clang-analyzer`? > > So check that ov7670_read() is successful. > > The remaining static analysis problems are false positives. > There appears to be a limitation with checking the > aggregated returns. > > Signed-off-by: Tom Rix > --- > drivers/media/i2c/ov7670.c | 17 +++++++++++++---- > 1 file changed, 13 insertions(+), 4 deletions(-) > > diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c > index b42b289faaef..001d4b09db72 100644 > --- a/drivers/media/i2c/ov7670.c > +++ b/drivers/media/i2c/ov7670.c > @@ -929,6 +929,8 @@ static int ov7670_set_hw(struct v4l2_subdev *sd, int hstart, int hstop, > ret = ov7670_write(sd, REG_HSTART, (hstart >> 3) & 0xff); > ret += ov7670_write(sd, REG_HSTOP, (hstop >> 3) & 0xff); > ret += ov7670_read(sd, REG_HREF, &v); > + if (ret) > + return ret; > v = (v & 0xc0) | ((hstop & 0x7) << 3) | (hstart & 0x7); > msleep(10); > ret += ov7670_write(sd, REG_HREF, v); > @@ -938,6 +940,8 @@ static int ov7670_set_hw(struct v4l2_subdev *sd, int hstart, int hstop, > ret += ov7670_write(sd, REG_VSTART, (vstart >> 2) & 0xff); > ret += ov7670_write(sd, REG_VSTOP, (vstop >> 2) & 0xff); > ret += ov7670_read(sd, REG_VREF, &v); > + if (ret) > + return ret; > v = (v & 0xf0) | ((vstop & 0x3) << 2) | (vstart & 0x3); > msleep(10); > ret += ov7670_write(sd, REG_VREF, v); > @@ -1460,6 +1464,8 @@ static int ov7670_g_gain(struct v4l2_subdev *sd, __s32 *value) > unsigned char gain; > > ret = ov7670_read(sd, REG_GAIN, &gain); > + if (ret) > + return ret; > *value = gain; > return ret; > } > @@ -1470,11 +1476,14 @@ static int ov7670_s_gain(struct v4l2_subdev *sd, int value) > unsigned char com8; > > ret = ov7670_write(sd, REG_GAIN, value & 0xff); > + if (ret) > + return ret; > /* Have to turn off AGC as well */ > - if (ret == 0) { > - ret = ov7670_read(sd, REG_COM8, &com8); > - ret = ov7670_write(sd, REG_COM8, com8 & ~COM8_AGC); > - } > + ret = ov7670_read(sd, REG_COM8, &com8); > + if (ret) > + return ret; > + ret = ov7670_write(sd, REG_COM8, com8 & ~COM8_AGC); > + > return ret; > } > > -- > 2.18.1 > -- Thanks, ~Nick Desaulniers