On Mon, Jun 01, 2015 at 11:10:50PM +0200, Richard Weinberger wrote:
> kasprintf() used in get_partition_name() does a dynamic
> memory allocation and can fail. We have to handle that case.
> 
> Signed-off-by: Richard Weinberger <[email protected]>
> ---
>  drivers/mtd/nand/nandsim.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
> index f232427..52c0c1a 100644
> --- a/drivers/mtd/nand/nandsim.c
> +++ b/drivers/mtd/nand/nandsim.c
> @@ -743,6 +743,11 @@ static int init_nandsim(struct mtd_info *mtd)
>                       goto error;
>               }
>               ns->partitions[i].name   = get_partition_name(i);
> +             if (!ns->partitions[i].name) {
> +                     NS_ERR("unable to allocate memory.\n");

Probably don't really need the allocation failure messages. But this
matches the current style, so we can just rip the messages out at
another time.

> +                     ret = -ENOMEM;
> +                     goto error;
> +             }
>               ns->partitions[i].offset = next_offset;
>               ns->partitions[i].size   = part_sz;
>               next_offset += ns->partitions[i].size;
> @@ -756,6 +761,11 @@ static int init_nandsim(struct mtd_info *mtd)
>                       goto error;
>               }
>               ns->partitions[i].name   = get_partition_name(i);
> +             if (!ns->partitions[i].name) {
> +                     NS_ERR("unable to allocate memory.\n");

Same here.

> +                     ret = -ENOMEM;
> +                     goto error;
> +             }
>               ns->partitions[i].offset = next_offset;
>               ns->partitions[i].size   = remains;
>               ns->nbparts += 1;

Brian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to