* [PATCH] efi_driver: fix a wrong cast
@ 2021-09-27 4:30 AKASHI Takahiro
2021-09-27 7:48 ` Heinrich Schuchardt
0 siblings, 1 reply; 3+ messages in thread
From: AKASHI Takahiro @ 2021-09-27 4:30 UTC (permalink / raw)
To: xypron.glpk, agraf; +Cc: u-boot, AKASHI Takahiro
struct efi_driver_binding_protocol, i.e. bp, is not the first element
in struct efi_driver_binding_extended_protocol.
So the casting:
struct efi_driver_binding_extended_protocol *bp =
(struct efi_driver_binding_extended_protocol *)this;
is simply wrong.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
lib/efi_driver/efi_uclass.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/lib/efi_driver/efi_uclass.c b/lib/efi_driver/efi_uclass.c
index 382c2b477f4d..9e784f9c237f 100644
--- a/lib/efi_driver/efi_uclass.c
+++ b/lib/efi_driver/efi_uclass.c
@@ -65,8 +65,8 @@ static efi_status_t EFIAPI efi_uc_supported(
{
efi_status_t r, ret;
void *interface;
- struct efi_driver_binding_extended_protocol *bp =
- (struct efi_driver_binding_extended_protocol *)this;
+ struct efi_driver_binding_extended_protocol *bp = container_of(this,
+ struct efi_driver_binding_extended_protocol, bp);
EFI_ENTRY("%p, %p, %ls", this, controller_handle,
efi_dp_str(remaining_device_path));
@@ -113,8 +113,8 @@ static efi_status_t EFIAPI efi_uc_start(
{
efi_status_t r, ret;
void *interface = NULL;
- struct efi_driver_binding_extended_protocol *bp =
- (struct efi_driver_binding_extended_protocol *)this;
+ struct efi_driver_binding_extended_protocol *bp = container_of(this,
+ struct efi_driver_binding_extended_protocol, bp);
EFI_ENTRY("%p, %p, %ls", this, controller_handle,
efi_dp_str(remaining_device_path));
@@ -201,8 +201,8 @@ static efi_status_t EFIAPI efi_uc_stop(
efi_status_t ret;
efi_uintn_t count;
struct efi_open_protocol_info_entry *entry_buffer;
- struct efi_driver_binding_extended_protocol *bp =
- (struct efi_driver_binding_extended_protocol *)this;
+ struct efi_driver_binding_extended_protocol *bp = container_of(this,
+ struct efi_driver_binding_extended_protocol, bp);
EFI_ENTRY("%p, %p, %zu, %p", this, controller_handle,
number_of_children, child_handle_buffer);
@@ -283,7 +283,7 @@ static efi_status_t efi_add_driver(struct driver *drv)
}
bp->bp.image_handle = bp->bp.driver_binding_handle;
ret = efi_add_protocol(bp->bp.driver_binding_handle,
- &efi_guid_driver_binding_protocol, bp);
+ &efi_guid_driver_binding_protocol, &bp->bp);
if (ret != EFI_SUCCESS) {
efi_delete_handle(bp->bp.driver_binding_handle);
free(bp);
--
2.33.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] efi_driver: fix a wrong cast
2021-09-27 4:30 [PATCH] efi_driver: fix a wrong cast AKASHI Takahiro
@ 2021-09-27 7:48 ` Heinrich Schuchardt
2021-09-27 8:53 ` AKASHI Takahiro
0 siblings, 1 reply; 3+ messages in thread
From: Heinrich Schuchardt @ 2021-09-27 7:48 UTC (permalink / raw)
To: AKASHI Takahiro; +Cc: u-boot, agraf
On 9/27/21 6:30 AM, AKASHI Takahiro wrote:
> struct efi_driver_binding_protocol, i.e. bp, is not the first element
> in struct efi_driver_binding_extended_protocol.
> So the casting:
> struct efi_driver_binding_extended_protocol *bp =
> (struct efi_driver_binding_extended_protocol *)this;
> is simply wrong.
The definition in include/efi_driver.h is:
/*
* This structure adds internal fields to the driver binding protocol.
*/
struct efi_driver_binding_extended_protocol {
struct efi_driver_binding_protocol bp;
const struct efi_driver_ops *ops;
};
Why do you claim "bp is not the first element"?
The whole efi_driver code relies on the fact that the
efi_driver_binding_extended_protocol can be interpreted as
efi_driver_binding_protocol.
Best regards
Heinrich
>
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> ---
> lib/efi_driver/efi_uclass.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/lib/efi_driver/efi_uclass.c b/lib/efi_driver/efi_uclass.c
> index 382c2b477f4d..9e784f9c237f 100644
> --- a/lib/efi_driver/efi_uclass.c
> +++ b/lib/efi_driver/efi_uclass.c
> @@ -65,8 +65,8 @@ static efi_status_t EFIAPI efi_uc_supported(
> {
> efi_status_t r, ret;
> void *interface;
> - struct efi_driver_binding_extended_protocol *bp =
> - (struct efi_driver_binding_extended_protocol *)this;
> + struct efi_driver_binding_extended_protocol *bp = container_of(this,
> + struct efi_driver_binding_extended_protocol, bp);
>
> EFI_ENTRY("%p, %p, %ls", this, controller_handle,
> efi_dp_str(remaining_device_path));
> @@ -113,8 +113,8 @@ static efi_status_t EFIAPI efi_uc_start(
> {
> efi_status_t r, ret;
> void *interface = NULL;
> - struct efi_driver_binding_extended_protocol *bp =
> - (struct efi_driver_binding_extended_protocol *)this;
> + struct efi_driver_binding_extended_protocol *bp = container_of(this,
> + struct efi_driver_binding_extended_protocol, bp);
>
> EFI_ENTRY("%p, %p, %ls", this, controller_handle,
> efi_dp_str(remaining_device_path));
> @@ -201,8 +201,8 @@ static efi_status_t EFIAPI efi_uc_stop(
> efi_status_t ret;
> efi_uintn_t count;
> struct efi_open_protocol_info_entry *entry_buffer;
> - struct efi_driver_binding_extended_protocol *bp =
> - (struct efi_driver_binding_extended_protocol *)this;
> + struct efi_driver_binding_extended_protocol *bp = container_of(this,
> + struct efi_driver_binding_extended_protocol, bp);
>
> EFI_ENTRY("%p, %p, %zu, %p", this, controller_handle,
> number_of_children, child_handle_buffer);
> @@ -283,7 +283,7 @@ static efi_status_t efi_add_driver(struct driver *drv)
> }
> bp->bp.image_handle = bp->bp.driver_binding_handle;
> ret = efi_add_protocol(bp->bp.driver_binding_handle,
> - &efi_guid_driver_binding_protocol, bp);
> + &efi_guid_driver_binding_protocol, &bp->bp);
> if (ret != EFI_SUCCESS) {
> efi_delete_handle(bp->bp.driver_binding_handle);
> free(bp);
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] efi_driver: fix a wrong cast
2021-09-27 7:48 ` Heinrich Schuchardt
@ 2021-09-27 8:53 ` AKASHI Takahiro
0 siblings, 0 replies; 3+ messages in thread
From: AKASHI Takahiro @ 2021-09-27 8:53 UTC (permalink / raw)
To: Heinrich Schuchardt; +Cc: u-boot, agraf
On Mon, Sep 27, 2021 at 09:48:54AM +0200, Heinrich Schuchardt wrote:
>
>
> On 9/27/21 6:30 AM, AKASHI Takahiro wrote:
> > struct efi_driver_binding_protocol, i.e. bp, is not the first element
> > in struct efi_driver_binding_extended_protocol.
> > So the casting:
> > struct efi_driver_binding_extended_protocol *bp =
> > (struct efi_driver_binding_extended_protocol *)this;
> > is simply wrong.
>
> The definition in include/efi_driver.h is:
>
> /*
> * This structure adds internal fields to the driver binding protocol.
> */
> struct efi_driver_binding_extended_protocol {
> struct efi_driver_binding_protocol bp;
> const struct efi_driver_ops *ops;
> };
>
> Why do you claim "bp is not the first element"?
>
> The whole efi_driver code relies on the fact that the
> efi_driver_binding_extended_protocol can be interpreted as
> efi_driver_binding_protocol.
Oops, *I* have added some member elements in another patch.
(I'm trying to make efi_driver objects show up in DM tree.)
Please forget this patch for a while.
-Takahiro Akashi
> Best regards
>
> Heinrich
>
> >
> > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> > ---
> > lib/efi_driver/efi_uclass.c | 14 +++++++-------
> > 1 file changed, 7 insertions(+), 7 deletions(-)
> >
> > diff --git a/lib/efi_driver/efi_uclass.c b/lib/efi_driver/efi_uclass.c
> > index 382c2b477f4d..9e784f9c237f 100644
> > --- a/lib/efi_driver/efi_uclass.c
> > +++ b/lib/efi_driver/efi_uclass.c
> > @@ -65,8 +65,8 @@ static efi_status_t EFIAPI efi_uc_supported(
> > {
> > efi_status_t r, ret;
> > void *interface;
> > - struct efi_driver_binding_extended_protocol *bp =
> > - (struct efi_driver_binding_extended_protocol *)this;
> > + struct efi_driver_binding_extended_protocol *bp = container_of(this,
> > + struct efi_driver_binding_extended_protocol, bp);
> >
> > EFI_ENTRY("%p, %p, %ls", this, controller_handle,
> > efi_dp_str(remaining_device_path));
> > @@ -113,8 +113,8 @@ static efi_status_t EFIAPI efi_uc_start(
> > {
> > efi_status_t r, ret;
> > void *interface = NULL;
> > - struct efi_driver_binding_extended_protocol *bp =
> > - (struct efi_driver_binding_extended_protocol *)this;
> > + struct efi_driver_binding_extended_protocol *bp = container_of(this,
> > + struct efi_driver_binding_extended_protocol, bp);
> >
> > EFI_ENTRY("%p, %p, %ls", this, controller_handle,
> > efi_dp_str(remaining_device_path));
> > @@ -201,8 +201,8 @@ static efi_status_t EFIAPI efi_uc_stop(
> > efi_status_t ret;
> > efi_uintn_t count;
> > struct efi_open_protocol_info_entry *entry_buffer;
> > - struct efi_driver_binding_extended_protocol *bp =
> > - (struct efi_driver_binding_extended_protocol *)this;
> > + struct efi_driver_binding_extended_protocol *bp = container_of(this,
> > + struct efi_driver_binding_extended_protocol, bp);
> >
> > EFI_ENTRY("%p, %p, %zu, %p", this, controller_handle,
> > number_of_children, child_handle_buffer);
> > @@ -283,7 +283,7 @@ static efi_status_t efi_add_driver(struct driver *drv)
> > }
> > bp->bp.image_handle = bp->bp.driver_binding_handle;
> > ret = efi_add_protocol(bp->bp.driver_binding_handle,
> > - &efi_guid_driver_binding_protocol, bp);
> > + &efi_guid_driver_binding_protocol, &bp->bp);
> > if (ret != EFI_SUCCESS) {
> > efi_delete_handle(bp->bp.driver_binding_handle);
> > free(bp);
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-09-27 8:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27 4:30 [PATCH] efi_driver: fix a wrong cast AKASHI Takahiro
2021-09-27 7:48 ` Heinrich Schuchardt
2021-09-27 8:53 ` AKASHI Takahiro
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.