[PATCH 1/3] crypto: add enum
Marc Kleine-Budde
mkl at pengutronix.de
Wed Jan 6 06:39:47 PST 2016
On 01/05/2016 05:54 PM, Sam Ravnborg wrote:
> On Tue, Jan 05, 2016 at 09:11:01AM +0100, Marc Kleine-Budde wrote:
>> From: Sascha Hauer <s.hauer at pengutronix.de>
>>
>> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
>> Signed-off-by: Marc Kleine-Budde <mkl at pengutronix.de>
>
> The subject and the patch description could use some
> more love and care.
Good idea.
>> diff --git a/crypto/digest.c b/crypto/digest.c
>> index a90e4ff79f89..46600f246ece 100644
>> --- a/crypto/digest.c
>> +++ b/crypto/digest.c
>> @@ -116,7 +116,27 @@ static struct digest_algo *digest_algo_get_by_name(const char *name)
>> list_for_each_entry(tmp, &digests, list) {
>> if (strcmp(tmp->base.name, name) != 0)
>> continue;
>> -
>> +
>> + if (tmp->base.priority <= priority)
>> + continue;
>> +
>> + d = tmp;
>> + priority = tmp->base.priority;
>> + }
>> +
>> + return d;
>> +}
>> +
>> +static struct digest_algo *digest_algo_get_by_algo(enum hash_algo algo)
>> +{
>> + struct digest_algo *d = NULL;
>> + struct digest_algo *tmp;
>> + int priority = -1;
>> +
>> + list_for_each_entry(tmp, &digests, list) {
>> + if (tmp->base.algo != algo)
>> + continue;
>> +
>> if (tmp->base.priority <= priority)
>> continue;
>>
>> @@ -160,6 +180,27 @@ struct digest *digest_alloc(const char *name)
>> }
>> EXPORT_SYMBOL_GPL(digest_alloc);
>>
>> +struct digest *digest_alloc_by_algo(enum hash_algo hash_algo)
>> +{
>> + struct digest *d;
>> + struct digest_algo *algo;
>> +
>> + algo = digest_algo_get_by_algo(hash_algo);
>> + if (!algo)
>> + return NULL;
>> +
>> + d = xzalloc(sizeof(*d));
>> + d->algo = algo;
>> + d->ctx = xzalloc(algo->ctx_length);
>
> Neither allocations are checked for failure.
If xzalloc fails barebox will go into OOM and throw a backtrace.
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20160106/c07ae037/attachment-0001.sig>
More information about the barebox
mailing list