mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] efi: load the protocol expected by the driver
@ 2017-03-11 16:07 Michael Olbrich
  2017-03-11 16:07 ` [PATCH 2/2] efi: only iterate over handles that provide the device path protocol Michael Olbrich
  2017-03-14  7:13 ` [PATCH 1/2] efi: load the protocol expected by the driver Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Michael Olbrich @ 2017-03-11 16:07 UTC (permalink / raw)
  To: barebox; +Cc: Michael Olbrich

The drivers are loaded if any guid provided by the device matches. So load
the protocol for the matched guid and not for the first guid.
Otherwise the driver may cast the protocol to the wrong type and proably
crash.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
---
 drivers/efi/efi-device.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index 959878e7f5cf..c5fb404cd36b 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -184,8 +184,6 @@ static struct efi_device *efi_add_device(efi_handle_t *handle, efi_guid_t **guid
 	efidev->dev.info = efi_devinfo;
 	efidev->devpath = devpath;
 
-	BS->handle_protocol(handle, &guidarr[0], &efidev->protocol);
-
 	sprintf(efidev->dev.name, "handle-%p", handle);
 
 	efidev->parent_handle = efi_find_parent(efidev->handle);
@@ -311,8 +309,11 @@ static int efi_bus_match(struct device_d *dev, struct driver_d *drv)
 	int i;
 
 	for (i = 0; i < efidev->num_guids; i++) {
-		if (!memcmp(&efidrv->guid, &efidev->guids[i], sizeof(efi_guid_t)))
+		if (!memcmp(&efidrv->guid, &efidev->guids[i], sizeof(efi_guid_t))) {
+			BS->handle_protocol(efidev->handle, &efidev->guids[i],
+					&efidev->protocol);
 			return 0;
+		}
 	}
 
 	return 1;
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] efi: only iterate over handles that provide the device path protocol
  2017-03-11 16:07 [PATCH 1/2] efi: load the protocol expected by the driver Michael Olbrich
@ 2017-03-11 16:07 ` Michael Olbrich
  2017-03-14  7:13 ` [PATCH 1/2] efi: load the protocol expected by the driver Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Olbrich @ 2017-03-11 16:07 UTC (permalink / raw)
  To: barebox; +Cc: Michael Olbrich

All other handled are skipped anyways.

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
---
 drivers/efi/efi-device.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index c5fb404cd36b..db3c0afe3361 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -102,7 +102,8 @@ static efi_handle_t *efi_find_parent(efi_handle_t *handle)
 	struct efi_open_protocol_information_entry *entry_buffer;
 	unsigned long entry_count;
 
-	ret = efi_locate_handle(all_handles, NULL, NULL, &handle_count, &handles);
+	ret = efi_locate_handle(by_protocol, &efi_device_path_protocol_guid,
+			NULL, &handle_count, &handles);
 	if (ret)
 		return NULL;
 
@@ -244,7 +245,8 @@ void efi_register_devices(void)
 	struct efi_device **efidevs;
 	int registered;
 
-	ret = efi_locate_handle(all_handles, NULL, NULL, &handle_count, &handles);
+	ret = efi_locate_handle(by_protocol, &efi_device_path_protocol_guid,
+			NULL, &handle_count, &handles);
 	if (ret)
 		return;
 
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] efi: load the protocol expected by the driver
  2017-03-11 16:07 [PATCH 1/2] efi: load the protocol expected by the driver Michael Olbrich
  2017-03-11 16:07 ` [PATCH 2/2] efi: only iterate over handles that provide the device path protocol Michael Olbrich
@ 2017-03-14  7:13 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2017-03-14  7:13 UTC (permalink / raw)
  To: Michael Olbrich; +Cc: barebox

On Sat, Mar 11, 2017 at 05:07:32PM +0100, Michael Olbrich wrote:
> The drivers are loaded if any guid provided by the device matches. So load
> the protocol for the matched guid and not for the first guid.
> Otherwise the driver may cast the protocol to the wrong type and proably
> crash.
> 
> Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
> ---
>  drivers/efi/efi-device.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
> index 959878e7f5cf..c5fb404cd36b 100644
> --- a/drivers/efi/efi-device.c
> +++ b/drivers/efi/efi-device.c
> @@ -184,8 +184,6 @@ static struct efi_device *efi_add_device(efi_handle_t *handle, efi_guid_t **guid
>  	efidev->dev.info = efi_devinfo;
>  	efidev->devpath = devpath;
>  
> -	BS->handle_protocol(handle, &guidarr[0], &efidev->protocol);
> -
>  	sprintf(efidev->dev.name, "handle-%p", handle);
>  
>  	efidev->parent_handle = efi_find_parent(efidev->handle);
> @@ -311,8 +309,11 @@ static int efi_bus_match(struct device_d *dev, struct driver_d *drv)
>  	int i;
>  
>  	for (i = 0; i < efidev->num_guids; i++) {
> -		if (!memcmp(&efidrv->guid, &efidev->guids[i], sizeof(efi_guid_t)))
> +		if (!memcmp(&efidrv->guid, &efidev->guids[i], sizeof(efi_guid_t))) {
> +			BS->handle_protocol(efidev->handle, &efidev->guids[i],
> +					&efidev->protocol);
>  			return 0;
> +		}
>  	}
>  
>  	return 1;
> -- 
> 2.11.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-14  7:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-11 16:07 [PATCH 1/2] efi: load the protocol expected by the driver Michael Olbrich
2017-03-11 16:07 ` [PATCH 2/2] efi: only iterate over handles that provide the device path protocol Michael Olbrich
2017-03-14  7:13 ` [PATCH 1/2] efi: load the protocol expected by the driver Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox