Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp704119pxu; Thu, 3 Dec 2020 10:28:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJx6c0XI67XXgnq4Z+kjFBUXsbBhD6Q3nRlg68aAu1/jpxPgydANPQZ0qOSWUZe184eoG3kq X-Received: by 2002:a50:dac7:: with SMTP id s7mr4046299edj.106.1607020137068; Thu, 03 Dec 2020 10:28:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607020137; cv=none; d=google.com; s=arc-20160816; b=WTWQ3Ln++5sGR9zHIsC4NiL4LSDPFQ47gdYVuS5Sp5I8ro+zJY5HXmvYVty8KN0Wz6 otiCeFy5IjrbPk6iM3C2EJ8eIu532EnBRqjf2W3xqtqYsfU0G+Xm65wELNOvO5Y6/RUJ VnNJabT8cThbSpPSnrHaM0MEnh9wXpyLt9qxOx6+hvOp8HcMXEmfADS3Tf2oz3FY8YzI OtolpNeztY3+3FMGyYZwHrDFydj4OzW7URW7/1RZbDyME3omUq+shmbLA1iuB4Q6F3d9 qkI3i5oWzQtI90L0ujYx3SgmJEWN2PP+WeEDBMi3KF2eaoyG1GhVp/ql+DSMtrI4AFAe dZog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=ZIBE80QOXFjSgHZnQKR0O4u0X8Pf3ueD4zIsNqNRl1U=; b=jhPmp81vXTToZExKZjSySm4eKl6yrubZKF/CIjrclamZlgxwh+lS8kPnO51zmniJPX 80GDcEt1sS23aP7FbMM2k+HUy//aQ9VY9Mp1C3LGR6T4562OObULaQ6jMnwQcH/M9kea jkLB0oaUkgDEuDMessV6mFG2YuCoVSBBAoj0CwwbaggJT6tX0QN0GUUBl+ZeR6hk6sQ1 r2wIFCbwrxoz6gfJEkblLkbRNLyPspm04wgwTi2amBxM2dJYaxOj9UG4EUaA5Gd/Trgs J1Mf1GihrX1L3hPEDY5m6aY4tHBKKuJfpikzKlfXGWxQkZKad17pT0t+lN4phI4090ht YxUA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ch11si1415324edb.384.2020.12.03.10.28.34; Thu, 03 Dec 2020 10:28:57 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502042AbgLCSZQ (ORCPT + 99 others); Thu, 3 Dec 2020 13:25:16 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:34072 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731594AbgLCSZK (ORCPT ); Thu, 3 Dec 2020 13:25:10 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212]) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kktHG-0000p3-Ro; Thu, 03 Dec 2020 18:24:26 +0000 Subject: Re: media: i2c: add OV02A10 image sensor driver To: Andy Shevchenko Cc: Dongchun Zhu , 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" References: <9af089ea-2532-68ac-5d22-97a669ccec91@canonical.com> From: Colin Ian King Message-ID: <8eb453c7-a221-e741-5fe5-655e59075f34@canonical.com> Date: Thu, 3 Dec 2020 18:24:26 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/12/2020 18:10, 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: > 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. > Not sure I fully understand how that fixes it. Given that ret is currently not initialized when we hit: if (ov02a10->streaming == on) goto unlock_and_return; either we initialize ret to 0 at the start of the function, or do: if (ov02a10->streaming == on) { ret = 0; goto unlock_and_return; } (assuming the intention is to return zero for this specific case). Colin