ACK: [PATCH 2/2] efi_runtime: reuse the in-kernel guid structure

Alex Hung alex.hung at canonical.com
Wed Jul 6 02:03:04 UTC 2016


On 2016-07-04 05:25 PM, Ivan Hu wrote:
> reuse the in-kernel guid structure efi_guid_t instead of making our own one.
>
> Signed-off-by: Ivan Hu <ivan.hu at canonical.com>
> ---
>   efi_runtime/efi_runtime.c | 49 ++++++++---------------------------------------
>   efi_runtime/efi_runtime.h | 17 ++++++----------
>   2 files changed, 14 insertions(+), 52 deletions(-)
>
> diff --git a/efi_runtime/efi_runtime.c b/efi_runtime/efi_runtime.c
> index 9e1fb87..115b1b5 100644
> --- a/efi_runtime/efi_runtime.c
> +++ b/efi_runtime/efi_runtime.c
> @@ -74,32 +74,6 @@ static void convert_to_efi_time(efi_time_t *eft, EFI_TIME *time)
>   	eft->pad2 = time->Pad2;
>   }
>
> -static void convert_from_guid(efi_guid_t *vendor, EFI_GUID *vendor_guid)
> -{
> -	int i;
> -	for (i = 0; i < 16; i++) {
> -		if (i < 4)
> -			vendor->b[i] = (vendor_guid->Data1 >> (8*i)) & 0xff;
> -		else if (i < 6)
> -			vendor->b[i] = (vendor_guid->Data2 >> (8*(i-4))) & 0xff;
> -		else if (i < 8)
> -			vendor->b[i] = (vendor_guid->Data3 >> (8*(i-6))) & 0xff;
> -		else
> -			vendor->b[i] = (vendor_guid->Data4[i-8]);
> -	}
> -}
> -
> -static void convert_to_guid(efi_guid_t *vendor, EFI_GUID *vendor_guid)
> -{
> -	int i;
> -	vendor_guid->Data1 = vendor->b[0] + (vendor->b[1] << 8) +
> -				(vendor->b[2] << 16) + (vendor->b[3] << 24);
> -	vendor_guid->Data2 = vendor->b[4] + (vendor->b[5] << 8);
> -	vendor_guid->Data3 = vendor->b[6] + (vendor->b[7] << 8);
> -	for (i = 0; i < 8; i++)
> -		vendor_guid->Data4[i] = vendor->b[i+8];
> -}
> -
>   /*
>    * Count the bytes in 'str', including the terminating NULL.
>    *
> @@ -238,7 +212,7 @@ static long efi_runtime_get_variable(unsigned long arg)
>   	struct efi_getvariable __user *getvariable;
>   	struct efi_getvariable getvariable_local;
>   	unsigned long datasize, prev_datasize, *dz;
> -	efi_guid_t vendor, *vd = NULL;
> +	efi_guid_t vendor_guid, *vd = NULL;
>   	efi_status_t status;
>   	uint16_t *name = NULL;
>   	uint32_t attr, *at;
> @@ -254,13 +228,11 @@ static long efi_runtime_get_variable(unsigned long arg)
>   	    get_user(datasize, getvariable_local.DataSize))
>   		return -EFAULT;
>   	if (getvariable_local.VendorGuid) {
> -		EFI_GUID vendor_guid;
>
>   		if (copy_from_user(&vendor_guid, getvariable_local.VendorGuid,
>   			   sizeof(vendor_guid)))
>   			return -EFAULT;
> -		convert_from_guid(&vendor, &vendor_guid);
> -		vd = &vendor;
> +		vd = &vendor_guid;
>   	}
>
>   	if (getvariable_local.VariableName) {
> @@ -312,8 +284,7 @@ static long efi_runtime_set_variable(unsigned long arg)
>   {
>   	struct efi_setvariable __user *setvariable;
>   	struct efi_setvariable setvariable_local;
> -	EFI_GUID vendor_guid;
> -	efi_guid_t vendor;
> +	efi_guid_t vendor_guid;
>   	efi_status_t status;
>   	uint16_t *name;
>   	void *data;
> @@ -328,8 +299,6 @@ static long efi_runtime_set_variable(unsigned long arg)
>   			   sizeof(vendor_guid)))
>   		return -EFAULT;
>
> -	convert_from_guid(&vendor, &vendor_guid);
> -
>   	rv = copy_ucs2_from_user(&name, setvariable_local.VariableName);
>   	if (rv)
>   		return rv;
> @@ -346,7 +315,7 @@ static long efi_runtime_set_variable(unsigned long arg)
>   		return -EFAULT;
>   	}
>
> -	status = efi.set_variable(name, &vendor, setvariable_local.Attributes,
> +	status = efi.set_variable(name, &vendor_guid, setvariable_local.Attributes,
>   				  setvariable_local.DataSize, data);
>
>   	kfree(data);
> @@ -486,8 +455,8 @@ static long efi_runtime_get_nextvariablename(unsigned long arg)
>   	struct efi_getnextvariablename getnextvariablename_local;
>   	unsigned long name_size, prev_name_size = 0, *ns = NULL;
>   	efi_status_t status;
> -	efi_guid_t vendor, *vd = NULL;
> -	EFI_GUID vendor_guid;
> +	efi_guid_t *vd = NULL;
> +	efi_guid_t vendor_guid;
>   	uint16_t *name = NULL;
>   	int rv;
>
> @@ -509,8 +478,7 @@ static long efi_runtime_get_nextvariablename(unsigned long arg)
>   		if (copy_from_user(&vendor_guid, getnextvariablename_local.VendorGuid,
>   			   sizeof(vendor_guid)))
>   			return -EFAULT;
> -		convert_from_guid(&vendor, &vendor_guid);
> -		vd = &vendor;
> +		vd = &vendor_guid;
>   	}
>
>   	if (getnextvariablename_local.VariableName) {
> @@ -552,9 +520,8 @@ static long efi_runtime_get_nextvariablename(unsigned long arg)
>   	}
>
>   	if (vd) {
> -		convert_to_guid(vd, &vendor_guid);
>   		if (copy_to_user(getnextvariablename_local.VendorGuid,
> -				 &vendor_guid, sizeof(EFI_GUID)))
> +				 vd, sizeof(efi_guid_t)))
>   			return -EFAULT;
>   	}
>
> diff --git a/efi_runtime/efi_runtime.h b/efi_runtime/efi_runtime.h
> index 149a179..092e842 100644
> --- a/efi_runtime/efi_runtime.h
> +++ b/efi_runtime/efi_runtime.h
> @@ -21,6 +21,8 @@
>   #ifndef _EFI_RUNTIME_H_
>   #define _EFI_RUNTIME_H_
>
> +#include <linux/efi.h>
> +
>   typedef enum {
>   	EfiResetCold,
>   	EfiResetWarm,
> @@ -28,13 +30,6 @@ typedef enum {
>   } EFI_RESET_TYPE;
>
>   typedef struct {
> -	uint32_t	Data1;
> -	uint16_t	Data2;
> -	uint16_t	Data3;
> -	uint8_t		Data4[8];
> -} __attribute__ ((packed)) EFI_GUID;
> -
> -typedef struct {
>   	uint16_t	Year;		/* 1900 – 9999 */
>   	uint8_t		Month;		/* 1 – 12 */
>   	uint8_t		Day;		/* 1 – 31 */
> @@ -55,7 +50,7 @@ typedef struct {
>   } __attribute__ ((packed)) EFI_TIME_CAPABILITIES;
>
>   typedef struct {
> -	EFI_GUID CapsuleGuid;
> +	efi_guid_t CapsuleGuid;
>   	uint32_t HeaderSize;
>   	uint32_t Flags;
>   	uint32_t CapsuleImageSize;
> @@ -63,7 +58,7 @@ typedef struct {
>
>   struct efi_getvariable {
>   	uint16_t	*VariableName;
> -	EFI_GUID	*VendorGuid;
> +	efi_guid_t	*VendorGuid;
>   	uint32_t	*Attributes;
>   	uint64_t	*DataSize;
>   	void		*Data;
> @@ -72,7 +67,7 @@ struct efi_getvariable {
>
>   struct efi_setvariable {
>   	uint16_t	*VariableName;
> -	EFI_GUID	*VendorGuid;
> +	efi_guid_t	*VendorGuid;
>   	uint32_t	Attributes;
>   	uint64_t	DataSize;
>   	void		*Data;
> @@ -82,7 +77,7 @@ struct efi_setvariable {
>   struct efi_getnextvariablename {
>   	uint64_t	*VariableNameSize;
>   	uint16_t	*VariableName;
> -	EFI_GUID	*VendorGuid;
> +	efi_guid_t	*VendorGuid;
>   	uint64_t	*status;
>   } __attribute__ ((packed));
>
>
>
>

Acked-by: Alex Hung <alex.hung at canonical.com>



More information about the fwts-devel mailing list