linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Biju Das <biju.das@bp.renesas.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	"kbuild@01.org" <kbuild@01.org>,
	"kbuild-all@01.org" <kbuild-all@01.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [kbuild] [usb:usb-next 32/38] drivers/usb/typec/hd3ss3220.c:182 hd3ss3220_probe() warn: passing zero to 'PTR_ERR'
Date: Mon, 7 Oct 2019 16:17:17 +0300	[thread overview]
Message-ID: <20191007131717.GJ21515@kadam> (raw)
In-Reply-To: <OSBPR01MB2103ECC1BA7A7A0D9ABA15CBB89B0@OSBPR01MB2103.jpnprd01.prod.outlook.com>

On Mon, Oct 07, 2019 at 12:36:10PM +0000, Biju Das wrote:
> > err_unreg_port:
> > 	typec_unregister_port(hd3ss3220->port);
> > err_put_role:
> > 	usb_role_switch_put(hd3ss3220->role_sw);
> > err_put_handle:
> > 	fwnode_handle_put(foo bar);
> >
> > 	return ret;
> > The rule behind this style of error handling is that you just have to keep track
> > of the most recently allocated resource and at the bottom you free them in
> > the reverse order from how you allocated them.  Here we had allocated -
> > >role_sw but the typec_register_port() so we do goto free_role_sw;  Now
> > people can guess what the goto does because the name is descriptive and
> > since it matches the most recently allocated resource that means it's okay.
> 
> Yes I agree. But In this case, only one error label is sufficient.

Yes.  You could fix the leak by passing an invalid pointer to
typec_unregister_port() but that way is asking for trouble in the
future...  These are the kinds of bugs I fix all the time because I'm
working with static analysis.  Clearly defined error labels are more
readable and less bug prone.

regards,
dan carpenter

  reply	other threads:[~2019-10-07 13:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-07 11:29 [kbuild] [usb:usb-next 32/38] drivers/usb/typec/hd3ss3220.c:182 hd3ss3220_probe() warn: passing zero to 'PTR_ERR' Dan Carpenter
2019-10-07 12:36 ` Biju Das
2019-10-07 13:17   ` Dan Carpenter [this message]
2019-10-07 14:19     ` Biju Das
2019-10-07 14:33       ` Dan Carpenter
2019-10-07 14:51         ` Biju Das

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191007131717.GJ21515@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=biju.das@bp.renesas.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=kbuild-all@01.org \
    --cc=kbuild@01.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).