All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phillip Potter <phil@philpotter.co.uk>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: gregkh@linuxfoundation.org, Larry.Finger@lwfinger.net,
	paskripkin@gmail.com, martin@kaiser.cx, straube.linux@gmail.com,
	fmdefrancesco@gmail.com, abdun.nihaal@gmail.com,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] staging: r8188eu: convert rtw_set_802_11_add_wep error code semantics
Date: Sat, 30 Jul 2022 19:36:57 +0100	[thread overview]
Message-ID: <YuV452xuR1S0WyJi@OEMBP14.local> (raw)
In-Reply-To: <20220729064803.GT2338@kadam>

On Fri, Jul 29, 2022 at 09:48:03AM +0300, Dan Carpenter wrote:
> On Fri, Jul 29, 2022 at 12:11:50AM +0100, Phillip Potter wrote:
> > -u8 rtw_set_802_11_add_wep(struct adapter *padapter, struct ndis_802_11_wep *wep)
> > +int rtw_set_802_11_add_wep(struct adapter *padapter, struct ndis_802_11_wep *wep)
> >  {
> >  	int		keyid, res;
> >  	struct security_priv *psecuritypriv = &padapter->securitypriv;
> > -	u8		ret = _SUCCESS;
> > +	int		ret = 0;
> >  
> >  	keyid = wep->KeyIndex & 0x3fffffff;
> >  
> >  	if (keyid >= 4) {
> > -		ret = false;
> > +		ret = -EOPNOTSUPP;
> >  		goto exit;
> >  	}
> >  
> > @@ -424,7 +424,7 @@ u8 rtw_set_802_11_add_wep(struct adapter *padapter, struct ndis_802_11_wep *wep)
> >  	res = rtw_set_key(padapter, psecuritypriv, keyid, 1);
> >  
> >  	if (res == _FAIL)
> > -		ret = false;
> > +		ret = -ENOMEM;
> >  exit:
> >  
> >  	return ret;
> 
> No, this isn't right.  This now returns 1 on success and negative
> error codes on error.
> 
> There are a couple anti-patterns here:
> 
> 1) Do nothing gotos
> 2) Mixing error paths and success paths.
> 
> If you avoid mixing error paths and success paths then you get a pattern
> called: "Solid return zero."  This is where the end of the function has
> a very chunky "return 0;" to mark that it is successful.  You want that.
> Some people do a "if (ret == 0) return ret;".  Nope.  "return ret;" is
> not chunky.
> 
> regards,
> dan carpenter
> 

Hi Dan,

Thank you for the review firstly, much appreciated.

I'm happy of course to rewrite this to address any concerns, but
I was hoping I could clarify what you've said though? Apologies if I've
missed it, but how is this function now returning 1 on success? It sets
ret to 0 (success) at the start and then sets it to one of two negative
error codes depending on what happens. Am I missing something here?
(Perfectly possible that I am).

In terms of do nothing gotos, do you mean gotos that just set an error
code then jump to the end? If you'd prefer, as the function just returns
right after the exit label, I can just return the codes directly and have
a 'return 0;' like you say above?

Thanks as always for your insight.

Regards,
Phil

  reply	other threads:[~2022-07-30 18:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-28 23:11 [PATCH 0/2] staging: r8188eu: more error code cleanups Phillip Potter
2022-07-28 23:11 ` [PATCH 1/2] staging: r8188eu: remove initializer from ret in rtw_pwr_wakeup Phillip Potter
2022-07-28 23:11 ` [PATCH 2/2] staging: r8188eu: convert rtw_set_802_11_add_wep error code semantics Phillip Potter
2022-07-29  6:48   ` Dan Carpenter
2022-07-30 18:36     ` Phillip Potter [this message]
2022-07-31 17:12       ` Joe Perches
2022-08-01  9:17         ` Dan Carpenter
2022-08-02 23:26         ` Phillip Potter
2022-08-01  7:00       ` Dan Carpenter
2022-08-02 20:10   ` Pavel Skripkin
2022-08-02 22:15     ` Phillip Potter
2022-07-29  6:09 ` [PATCH 0/2] staging: r8188eu: more error code cleanups Philipp Hortmann

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=YuV452xuR1S0WyJi@OEMBP14.local \
    --to=phil@philpotter.co.uk \
    --cc=Larry.Finger@lwfinger.net \
    --cc=abdun.nihaal@gmail.com \
    --cc=dan.carpenter@oracle.com \
    --cc=fmdefrancesco@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=martin@kaiser.cx \
    --cc=paskripkin@gmail.com \
    --cc=straube.linux@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.