Hacker News new | ask | show | jobs
by wronskian 3411 days ago
The diff from the patch:

  - goto discard;
  + consume_skb(skb);
  + return 0;
One of the rare cases in the wild where a goto really was considered harmful! ;-)
2 comments

Rare? What about goto fail?
in 'goto fail', the problem looked like:

    if (foo() != 0)
      goto fail;
      goto fail;
That extra line of code could just as likely have been a return statement or anything else. The problem was not with the goto statement itself.

Edited to add: 'goto fail' is a valid construct and can be used to handle finalization in C functions. Consider:

    int
    foo(char *bar, int baz) {
      sometype_t *obj = NULL;
      int fd = -1;
      
      if ((obj = sometype_new(bar, baz)) == NULL) {
        goto fail;
      }
      if ((fd = open(sometype_path(obj), O_RDONLY)) < 0) {
        goto fail;
      }
      /* ... */
      return 0;
    fail:
      if (fd < 0) {
        close(fd);
      }
      if (obj != NULL) {
        sometype_free(obj);
      }
      return -1;
    }
There's nothing inherently wrong about that.
It is often much clearer to use goto than using a wrapper and switching on enum'ed return value to destruct a failed transaction.
"rare", not "non-existent". "goto fail", while well-known, is only one occurrence.
That was 3 years ago. And kernel code is covered in gotos.
Tbf, the return acts like a goto.