Re: [PATCH 1/2] crypto-testmgr: Use common error handling code in drbg_cavs_test()
From: Stephan Mueller
Date: Sat Oct 21 2017 - 15:07:55 EST
Am Samstag, 21. Oktober 2017, 19:53:54 CEST schrieb SF Markus Elfring:
Hi Markus,
> From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
> Date: Sat, 21 Oct 2017 19:29:11 +0200
>
> Adjust jump targets so that a bit of exception handling can be better
> reused at the end of this function.
>
> This issue was detected by using the Coccinelle software.
Thank you for this patch.
> -outbuf:
> + ret = memcmp(test->expected, buf, test->expectedlen);
> +free_rng:
> crypto_free_rng(drng);
> +free_buffer:
> kzfree(buf);
> return ret;
> +
> +report_failure:
> + pr_err("alg: drbg: could not obtain random data for driver %s\n",
> + driver);
> + goto free_rng;
Though, jumping back and forth like this with goto directives is something
that looks a bit strange. At least to my taste, may I suggest to have gotos
pointing only downwards and not up again? (Note, the same applies to the
ansi_cprng patch set).
What about something like following:
...
memcmp
goto free_rng;
report_failure:
<failure report>
free_rng:
<the deallocation code>
Ciao
Stephan