diff mbox series

[1/1] diskpart: check fdisk_create_disklabel return

Message ID 20210513071825.84780-1-james.hilliard1@gmail.com
State Accepted
Headers show
Series [1/1] diskpart: check fdisk_create_disklabel return | expand

Commit Message

James Hilliard May 13, 2021, 7:18 a.m. UTC
Since fdisk_create_disklabel can fail we should check the return
value and exit on failure.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
 handlers/diskpart_handler.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Stefano Babic May 13, 2021, 9:34 a.m. UTC | #1
On 13.05.21 09:18, James Hilliard wrote:
> Since fdisk_create_disklabel can fail we should check the return
> value and exit on failure.
> 
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
>   handlers/diskpart_handler.c | 12 ++++++++++--
>   1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c
> index 65010c1..63a46c6 100644
> --- a/handlers/diskpart_handler.c
> +++ b/handlers/diskpart_handler.c
> @@ -287,7 +287,11 @@ static int diskpart(struct img_type *img,
>   	if (!fdisk_has_label(cxt)) {
>   		WARN("%s does not contain a recognized partition table",
>   		     img->device);
> -		fdisk_create_disklabel(cxt, lbtype);
> +		ret = fdisk_create_disklabel(cxt, lbtype);
> +		if (ret) {
> +			ERROR("Failed to create disk label");
> +			goto handler_release;
> +		}
>   		createtable = true;
>   	} else if (lbtype) {
>   		if (!strcmp(lbtype, "gpt"))
> @@ -298,7 +302,11 @@ static int diskpart(struct img_type *img,
>   		if (!fdisk_is_labeltype(cxt, priv.labeltype)) {
>   			WARN("Partition table of different type, setting to %s, all data lost !",
>   				lbtype);
> -			fdisk_create_disklabel(cxt, lbtype);
> +			ret = fdisk_create_disklabel(cxt, lbtype);
> +			if (ret) {
> +				ERROR("Failed to create disk label");
> +				goto handler_release;
> +			}
>   			createtable = true;
>   		}
>   	}
> 

Reviewed-by: Stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c
index 65010c1..63a46c6 100644
--- a/handlers/diskpart_handler.c
+++ b/handlers/diskpart_handler.c
@@ -287,7 +287,11 @@  static int diskpart(struct img_type *img,
 	if (!fdisk_has_label(cxt)) {
 		WARN("%s does not contain a recognized partition table",
 		     img->device);
-		fdisk_create_disklabel(cxt, lbtype);
+		ret = fdisk_create_disklabel(cxt, lbtype);
+		if (ret) {
+			ERROR("Failed to create disk label");
+			goto handler_release;
+		}
 		createtable = true;
 	} else if (lbtype) {
 		if (!strcmp(lbtype, "gpt"))
@@ -298,7 +302,11 @@  static int diskpart(struct img_type *img,
 		if (!fdisk_is_labeltype(cxt, priv.labeltype)) {
 			WARN("Partition table of different type, setting to %s, all data lost !",
 				lbtype);
-			fdisk_create_disklabel(cxt, lbtype);
+			ret = fdisk_create_disklabel(cxt, lbtype);
+			if (ret) {
+				ERROR("Failed to create disk label");
+				goto handler_release;
+			}
 			createtable = true;
 		}
 	}