Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp135792pxu; Thu, 3 Dec 2020 22:26:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJxpktj9WsvKlGiRs7eOT4hK3RsQzaK1zjMoOS3gzHIeD80qLwVlZqNHPBGzOADpOcYvjaRU X-Received: by 2002:a17:906:e086:: with SMTP id gh6mr5536796ejb.95.1607063166125; Thu, 03 Dec 2020 22:26:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607063166; cv=none; d=google.com; s=arc-20160816; b=hF+IhtCCMib7E/tb5Jgn75xMw9IuPgoQMnPPAhst4m7KyAAcUMwIXlI8Ma6gcTYfj2 jd1ey+Jbo2WLBBGR+1v1cpwoffkqQvDRf4ov6kh2xNGAUBxzNcAgoIiAWGsV+iJ4VvUe ck7M3eKiL5kBavde9h2RcEdo7N68QPX+8j789tO9+3j8gTd/uf0uT6Mewh8xk4VeK1x3 uvYiTlEWwZs7ot2bV1mhZIUJmkhHDhwXJs2RlrQSA8PkQ+n4kACdtwxPOkAjzHuCF1hn fcORo3eBpqbIBrntpMw7iccYfj09LfUpnjS5zB+X02MCCFHIA60EFUY4lDQgFfTRbURR CjGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=98JkySW9/YPknIOP/vurrpriMRdU3Eb0izq2wDpGtMs=; b=MFRuBh7EPehy3SosRHCEwf88YC1SeUTiEpkmqltrExwe+7q4ZCP0Bcix4cNa0a5Gvz uYSfvwGJqHQGcboTnsFIdBZxT4EShgalWV/XLFlf360GGD2AbpfcznZHl1ed1JRcwKCl zT5pG/aI09ehFhABZqKnTfZV5rom+EagAoDMwcS/uf84Ffrx7WZIbqKHb4MNH+aPA46S v69CB47gpGbXBxQmOFKnflong+Jv3sH6z987Bh+L/myz/OGSEse/28Tc2B7bfWT7dNKl f5RAPhn2Z5LLBudqDIGq2Ex5IUkaSVI35bv6HCroNWR+91vI1K07nBcl1WOyg3PqgH5B U2GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ptlG2MEb; 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 nq4si920667ejb.115.2020.12.03.22.25.43; Thu, 03 Dec 2020 22:26:06 -0800 (PST) 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=ptlG2MEb; 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 S1728064AbgLDGY0 (ORCPT + 99 others); Fri, 4 Dec 2020 01:24:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbgLDGY0 (ORCPT ); Fri, 4 Dec 2020 01:24:26 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D3D5C061A4F for ; Thu, 3 Dec 2020 22:23:40 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id 91so223455wrj.7 for ; Thu, 03 Dec 2020 22:23:40 -0800 (PST) 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=98JkySW9/YPknIOP/vurrpriMRdU3Eb0izq2wDpGtMs=; b=ptlG2MEbVrPb2egLQW7XfjoIdnyFnJSEl5UOV3qQqSXT/R/9N5qJh785SkNjtSVafY eI5+ODstgUwiwtYUySnaBR+Yc1TSrmYFb2p77jCtkDub+G4YAANIA4qjFRAhpF4pinjq LBn9eCES70H/Rleg6etUGUaH+6TfwXpTH1aiEgsI17gT5vxOTf7YgafJSYqTzU47+L9h 1mYojfdBNMc5Nxn2K1fD7nSv7OS0k/ioAJRfHKXjUYOfdSa1Ltc+FU7t5+ncTAfoxUXT +vKLY4WHsptaZu5r0T7cOSJZIIzN96EYHHwaR8qyEVg7PZzCkfd9x/Q8cTa+wXS4yPaq x2gw== 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=98JkySW9/YPknIOP/vurrpriMRdU3Eb0izq2wDpGtMs=; b=Z/Qzvty17PjGim/g4zfO9fu6+CwE0hzCLV0LOFv+6fIu4vtSzz6Fc8OhQ5dRrZrymR MzTHxPl1i96QbxGArR+b118Ze7BBmlBELLpPdfi8vzcE3MSg8+AJDupGvjvT4gvPRKhe Im/mctNkhxUL3MKR9nQvtC5NCsN8PN3MpzDyB5J055NooOknzB748gfYjdu5cnUGIxUM QxXEXXizH1NQ1MU8Na730nsmfPVy5WJ0tmGhG4IRcvuuH9lKaat73DTpePTyEkFUnk5q SgyAMyFVI74zIs8xxeg1zDphdJR0DthhAINn63wqhncLDyI9RhQ2xRGbd+QBdgG7RHED 6slw== X-Gm-Message-State: AOAM530DfIb7V4VwmI89aZhKYe2mM9JNnzudzUceBugYgRG4+B6X8YU9 /0Y+4pWJPaPtjF3tK3kQ02eyLBTk6gJVizLzjddyxA== X-Received: by 2002:adf:e54f:: with SMTP id z15mr3093292wrm.159.1607063018670; Thu, 03 Dec 2020 22:23:38 -0800 (PST) MIME-Version: 1.0 References: <9af089ea-2532-68ac-5d22-97a669ccec91@canonical.com> <1607049966.4733.189.camel@mhfsdcap03> In-Reply-To: <1607049966.4733.189.camel@mhfsdcap03> From: Tomasz Figa Date: Fri, 4 Dec 2020 15:23:28 +0900 Message-ID: Subject: Re: media: i2c: add OV02A10 image sensor driver To: Dongchun Zhu Cc: Andy Shevchenko , Colin Ian King , Andy Shevchenko , Sakari Ailus , Mauro Carvalho Chehab , Matthias Brugger , linux-media , "linux-arm-kernel@lists.infradead.org" , "moderated list:ARM/Mediatek SoC support" , "linux-kernel@vger.kernel.org" , Sj Huang Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 4, 2020 at 11:47 AM Dongchun Zhu wrote: > > Hi Andy, > > On Thu, 2020-12-03 at 20:10 +0200, Andy Shevchenko wrote: > > On Thu, Dec 3, 2020 at 8:03 PM Colin Ian King wrote: > > > > > Static analysis on linux-next with Coverity has detected an issue with > > > the following commit: > > > > If you want to fix it properly, see my comments below... > > > > > 529 static int ov02a10_s_stream(struct v4l2_subdev *sd, int on) > > > 530 { > > > 531 struct ov02a10 *ov02a10 = to_ov02a10(sd); > > > 532 struct i2c_client *client = > > > v4l2_get_subdevdata(&ov02a10->subdev); > > > > > > 1. var_decl: Declaring variable ret without initializer. > > > > > > 533 int ret; > > > 534 > > > 535 mutex_lock(&ov02a10->mutex); > > > 536 > > > > > > 2. Condition ov02a10->streaming == on, taking true branch. > > > > > > 537 if (ov02a10->streaming == on) > > > > > > 3. Jumping to label unlock_and_return. > > > > > > 538 goto unlock_and_return; > > > 539 > > > 540 if (on) { > > > 541 ret = pm_runtime_get_sync(&client->dev); > > > 542 if (ret < 0) { > > > > > 543 pm_runtime_put_noidle(&client->dev); > > > 544 goto unlock_and_return; > > > > Instead of two above: > > From the document, pm_runtime_put_noidle is to decrease the runtime PM > usage counter of a device unless it is 0 already; while pm_runtime_put > would additionally run pm_request_idle to turn off the power if usage > counter is zero. > > So here maybe we can really use pm_runtime_put instead of > pm_runtime_put_noidle, although it seems that 'pm_runtime_get_sync' and > 'pm_runtime_put_noidle' often appear in pairs. > In an error state (e.g. if pm_runtime_get_sync() fails), pm_runtime_put() would decrement the usage counter and call rpm_idle() which would instantly return an error code. The end result would be the same, except that pm_runtime_put() would return a non-zero error code, but we ignore it anyway. However strange it looks, this seems to be an API guarantee, so Andy's suggestion is correct. Best regards, Tomasz > > goto err_rpm_put; > > > > > 545 } > > > 546 > > > 547 ret = __ov02a10_start_stream(ov02a10); > > > 548 if (ret) { > > > 549 __ov02a10_stop_stream(ov02a10); > > > 550 ov02a10->streaming = !on; > > > 551 goto err_rpm_put; > > > 552 } > > > 553 } else { > > > 554 __ov02a10_stop_stream(ov02a10); > > > 555 pm_runtime_put(&client->dev); > > > 556 } > > > 557 > > > 558 ov02a10->streaming = on; > > > > (1) > > > > > 559 mutex_unlock(&ov02a10->mutex); > > > 560 > > > 561 return 0; > > > 562 > > > 563 err_rpm_put: > > > 564 pm_runtime_put(&client->dev); > > > > > 565 unlock_and_return: > > > > Should be moved to (1). > > > > > 566 mutex_unlock(&ov02a10->mutex); > > > 567 > > > > > > Uninitialized scalar variable (UNINIT) > > > 4. uninit_use: Using uninitialized value ret. > > > > > > 568 return ret; > > > 569 } > > > > > > Variable ret has not been initialized, so the error return value is a > > > garbage value. It should be initialized with some appropriate negative > > > error code, or ret could be removed and the return should return a > > > literal value of a error code. > > > > > > I was unsure what value is appropriate to fix this, so instead I'm > > > reporting this issue. > > >