From: Alexander Aring <alex.aring@gmail.com>
To: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Cc: Martin Townsend <martin.townsend@xsilon.com>,
Martin Townsend <mtownsend1973@gmail.com>,
linux-zigbee-devel@lists.sourceforge.net,
linux-bluetooth@vger.kernel.org, linux-wpan@vger.kernel.org,
marcel@holtmann.org
Subject: Re: [PATCH v4 bluetooth] 6lowpan: fix incorrect return values in lowpan_rcv
Date: Tue, 16 Sep 2014 15:32:08 +0200 [thread overview]
Message-ID: <20140916133206.GA6104@omega> (raw)
In-Reply-To: <1410873619.4860.20.camel@jrissane-mobl.ger.corp.intel.com>
Hi Jukka,
On Tue, Sep 16, 2014 at 04:20:19PM +0300, Jukka Rissanen wrote:
> Hi Alex,
>
> On ti, 2014-09-16 at 14:48 +0200, Alexander Aring wrote:
> > Hi Martin,
> >
> > On Tue, Sep 16, 2014 at 01:40:24PM +0100, Martin Townsend wrote:
> > ...
> > >
> > > Yes I see the problem now, maybe it's better to revert back to skb_inout, less chance of introducing bugs and then we have a well defined return value.
> > >
> >
> > No problem, for me it's okay, if this is okay for Jukka, we can change
> > it later to a better behaviour. Jukka please answer what you think about this.
> >
>
> What about doing things like this in your example?
>
ehm yes, the example is only there to describe the current situation.
> > I also did a small c example because this now:
> >
> > char *foo(char *buf)
> > {
> > char *new;
> >
> > if (some_error)
> > return NULL;
>
> In this case you should probably not return NULL but something like
> -EINVAL
>
> if (some_error) {
> free(buf);
> return -EINVAL;
> }
yes, that's the second choice, let do consume_skb/kfree_skb inside
lowpan_process_data function.
>
> >
> > if (some_error)
> > return NULL;
>
> Ditto
>
> >
> > new = expand(buf, 23);
> > if (!new)
> > return NULL;
>
> if (!new) {
> free(buf);
> return -ENOMEM;
> }
>
> >
> > free(buf);
> > buf = new;
> >
> > /* buf is now different than the parameter buf */
> > if (some_error)
> > return NULL;
>
> if (some_error) {
> free(buf);
> return -EFOOBAR;
> }
>
> >
> > return buf;
> > }
> >
> > int main(int argc, const char *argv[])
> > {
> > char *local_buf = malloc(42);
> > char *buf;
> >
> > buf = foo(local_buf);
> > if (!buf) {
> > /* BUG */
> > /* we don't know if local_buf is still valid. */
> > free(local_buf);
> > }
>
> if (IS_ERR_OR_NULL(buf)) {
> fail();
> } else
> free(buf);
>
> >
> > return 0;
> > }
> >
> > I think if you do buf = foo(buf) you can rescue it but this doesn't
> > look like a clean solution for me.
> >
> > - Alex
>
>
> In this simplified example, the subroutine frees the buf which does not
> look nice I have to admit.
>
I am also fine with this solution. Make something I will review it and
look if we run into trouble.
In my last mails stands, that we have two choices:
- make the skb_inout thingy
- handle error freeing into lowpan_process_data function.
You described the last one now. :-)
- Alex
next prev parent reply other threads:[~2014-09-16 13:32 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-16 11:01 [PATCH v4 bluetooth] Fix lowpan_rcv Martin Townsend
2014-09-16 11:01 ` [PATCH v4 bluetooth] 6lowpan: fix incorrect return values in lowpan_rcv Martin Townsend
2014-09-16 11:09 ` Martin Townsend
2014-09-16 11:36 ` Alexander Aring
2014-09-16 11:39 ` Martin Townsend
2014-09-16 11:48 ` Alexander Aring
2014-09-16 11:53 ` Alexander Aring
2014-09-16 12:02 ` Alexander Aring
2014-09-16 12:18 ` Alexander Aring
2014-09-16 12:26 ` Martin Townsend
2014-09-16 12:34 ` Alexander Aring
2014-09-16 12:40 ` Martin Townsend
2014-09-16 12:48 ` Alexander Aring
2014-09-16 13:20 ` Jukka Rissanen
2014-09-16 13:32 ` Alexander Aring [this message]
2014-09-16 13:52 ` Jukka Rissanen
2014-09-16 14:05 ` Alexander Aring
2014-09-16 14:44 ` Martin Townsend
2014-09-16 17:38 ` Alexander Aring
2014-09-16 18:57 ` Martin Townsend
2014-09-16 19:37 ` Alexander Aring
2014-09-16 19:53 ` Martin Townsend
2014-09-16 20:07 ` Alexander Aring
2014-09-16 20:19 ` Martin Townsend
2014-09-16 20:30 ` Alexander Aring
2014-09-25 5:55 ` Alexander Aring
2014-09-25 7:25 ` Martin Townsend
2014-09-25 7:31 ` Alexander Aring
2014-09-25 7:39 ` Alexander Aring
2014-09-16 19:38 ` Martin Townsend
-- strict thread matches above, loose matches on Subject: below --
2014-10-01 12:10 [PATCH v4 bluetooth] Fix lowpan_rcv Martin Townsend
2014-10-01 12:10 ` [PATCH v4 bluetooth] 6lowpan: fix incorrect return values in lowpan_rcv Martin Townsend
2014-10-01 12:42 ` Alexander Aring
2014-10-02 12:43 ` Alexander Aring
2014-10-05 17:50 ` Alexander Aring
2014-10-05 17:58 ` Alexander Aring
2014-10-05 18:03 ` Alexander Aring
2014-10-05 21:00 ` Martin Townsend
2014-10-06 7:12 ` Alexander Aring
2014-10-06 8:27 ` Martin Townsend
2014-10-06 8:50 ` Marcel Holtmann
2014-10-06 8:35 ` Martin Townsend
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=20140916133206.GA6104@omega \
--to=alex.aring@gmail.com \
--cc=jukka.rissanen@linux.intel.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-wpan@vger.kernel.org \
--cc=linux-zigbee-devel@lists.sourceforge.net \
--cc=marcel@holtmann.org \
--cc=martin.townsend@xsilon.com \
--cc=mtownsend1973@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 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).