From patchwork Mon Dec 11 18:10:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10105645 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0F8C7602D8 for ; Mon, 11 Dec 2017 18:11:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 09A67295C6 for ; Mon, 11 Dec 2017 18:11:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F210129814; Mon, 11 Dec 2017 18:11:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 653AF295C6 for ; Mon, 11 Dec 2017 18:11:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751512AbdLKSLG (ORCPT ); Mon, 11 Dec 2017 13:11:06 -0500 Received: from osg.samsung.com ([64.30.133.232]:40432 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750707AbdLKSLG (ORCPT ); Mon, 11 Dec 2017 13:11:06 -0500 Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id BD7191B3C0; Mon, 11 Dec 2017 10:11:05 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at dev.s-opensource.com Received: from osg.samsung.com ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OIWT8bCNBcUN; Mon, 11 Dec 2017 10:11:03 -0800 (PST) Received: from vento.lan (177.205.74.193.dynamic.adsl.gvt.net.br [177.205.74.193]) by osg.samsung.com (Postfix) with ESMTPSA id 9AE081B3B8; Mon, 11 Dec 2017 10:11:01 -0800 (PST) Date: Mon, 11 Dec 2017 16:10:58 -0200 From: Mauro Carvalho Chehab To: Laurent Pinchart Cc: Linux Media Mailing List , Mauro Carvalho Chehab , Sakari Ailus , Hans Verkuil , Niklas =?UTF-8?B?U8O2ZGVybHVuZA==?= , Sebastian Reichel Subject: Re: [PATCH v2 08/26] media: v4l2-async: shut up an unitialized symbol warning Message-ID: <20171211161058.6cdedb7a@vento.lan> In-Reply-To: <1844403.anYkCZaVIn@avalon> References: <1844403.anYkCZaVIn@avalon> Organization: Samsung X-Mailer: Claws Mail 3.15.1-dirty (GTK+ 2.24.31; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Em Thu, 02 Nov 2017 04:51:40 +0200 Laurent Pinchart escreveu: > Hi Mauro, > > Thank you for the patch. > > On Wednesday, 1 November 2017 23:05:45 EET Mauro Carvalho Chehab wrote: > > Smatch reports this warning: > > drivers/media/v4l2-core/v4l2-async.c:597 v4l2_async_register_subdev() > > error: uninitialized symbol 'ret'. > > > > However, there's nothing wrong there. So, just shut up the > > warning. > > Nothing wrong, really ? ret does seem to be used uninitialized when the > function returns at the very last line. There's nothing wrong. If you follow the logic, you'll see that the line: return ret; is called only at "err_unbind" label, with is called only on two places: ret = v4l2_async_match_notify(notifier, v4l2_dev, sd, asd); if (ret) goto err_unbind; ret = v4l2_async_notifier_try_complete(notifier); if (ret) goto err_unbind; There, ret is defined. Yeah, the logic there is confusing. Thanks, Mauro media: v4l2-async: shut up an unitialized symbol warning Smatch reports this warning: drivers/media/v4l2-core/v4l2-async.c:597 v4l2_async_register_subdev() error: uninitialized symbol 'ret'. However, there's nothing wrong there. Yet, the logic is more complex than it should. So, rework it to make clearer about what happens when ret != 0. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/v4l2-core/v4l2-async.c | 38 +++++++++++++++-------------------- 1 file changed, 17 insertions(+), 21 deletions(-) --- patchwork.orig/drivers/media/v4l2-core/v4l2-async.c +++ patchwork/drivers/media/v4l2-core/v4l2-async.c @@ -532,7 +532,7 @@ int v4l2_async_register_subdev(struct v4 { struct v4l2_async_notifier *subdev_notifier; struct v4l2_async_notifier *notifier; - int ret; + int ret = 0; /* * No reference taken. The reference is held by the device @@ -560,11 +560,11 @@ int v4l2_async_register_subdev(struct v4 ret = v4l2_async_match_notify(notifier, v4l2_dev, sd, asd); if (ret) - goto err_unbind; + break; ret = v4l2_async_notifier_try_complete(notifier); if (ret) - goto err_unbind; + break; goto out_unlock; } @@ -572,26 +572,22 @@ int v4l2_async_register_subdev(struct v4 /* None matched, wait for hot-plugging */ list_add(&sd->async_list, &subdev_list); -out_unlock: - mutex_unlock(&list_lock); - - return 0; - -err_unbind: - /* - * Complete failed. Unbind the sub-devices bound through registering - * this async sub-device. - */ - subdev_notifier = v4l2_async_find_subdev_notifier(sd); - if (subdev_notifier) - v4l2_async_notifier_unbind_all_subdevs(subdev_notifier); - - if (sd->asd) - v4l2_async_notifier_call_unbind(notifier, sd, sd->asd); - v4l2_async_cleanup(sd); + if (ret) { + /* + * Complete failed. Unbind the sub-devices bound through registering + * this async sub-device. + */ + subdev_notifier = v4l2_async_find_subdev_notifier(sd); + if (subdev_notifier) + v4l2_async_notifier_unbind_all_subdevs(subdev_notifier); + + if (sd->asd) + v4l2_async_notifier_call_unbind(notifier, sd, sd->asd); + v4l2_async_cleanup(sd); + } +out_unlock: mutex_unlock(&list_lock); - return ret; } EXPORT_SYMBOL(v4l2_async_register_subdev);