This algorithm can use a lot of memory, so add a check for this condition and return the correct error. Signed-off-by: Simon Glass <simon.glass@canonical.com>