From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 464F8C433FE for ; Mon, 27 Sep 2021 07:49:10 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4F5C760F4F for ; Mon, 27 Sep 2021 07:49:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4F5C760F4F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3EFDE83282; Mon, 27 Sep 2021 09:49:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="isy2TVEF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0AB808328D; Mon, 27 Sep 2021 09:49:04 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5BEF083260 for ; Mon, 27 Sep 2021 09:49:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1632728939; bh=0hmNUziwsFaF/TMvccOqqE9K7p4mwrBXMm2LKz6IIK4=; h=X-UI-Sender-Class:Subject:To:Cc:References:From:Date:In-Reply-To; b=isy2TVEFSVshmhthhqCLJlnTfVwGFKi1PLMl4ZbXt9KU7/jb+ZNa+yrPunAihN1+g kYdYr+uBMm87gShhD8ScSpUL5e8YuK2u2XoiVCbgeK5T27CN3105w7WiaIA204hrKA 1ex3e0Y2FYiYW1+eMvaSsWhtR2tgtWCIz4Vmt7OU= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.123.55] ([88.152.144.157]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MwfWU-1mklpg43Sc-00y6Nw; Mon, 27 Sep 2021 09:48:59 +0200 Subject: Re: [PATCH] efi_driver: fix a wrong cast To: AKASHI Takahiro Cc: u-boot@lists.denx.de, agraf@csgraf.de References: <20210927043054.32727-1-takahiro.akashi@linaro.org> From: Heinrich Schuchardt Message-ID: <30faf0b0-237d-02f3-9e35-6e746f1b3f52@gmx.de> Date: Mon, 27 Sep 2021 09:48:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210927043054.32727-1-takahiro.akashi@linaro.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:jQAATxY3/81acBG7o27dUcBeFABWpYYdQtIYP5XvetjlGHt0TRm V3q6Hcxw8gSxcEvRSjQ4vbHjW3h8p51tYtPhiOQDmT9kGBu19ZJboU5Zdl3ZkLLn0kdD64R igsUIel8/2etqS8gM+SfSn/UnaQCTJ+0vZv0p68tHak3SSMl7mq6wtP8gJmfBLDiVwmtzGV QQrWqSW4HtFsJzAtFdltg== X-UI-Out-Filterresults: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F5AO1xVcLu g3gvhoOkAeI0CKQGL37bUaBZvhFG9L57EdMbicbSJXfBCOi5m48PHWd+46swFiDmW0NM12Jdx XISynmYLUiOaBw= X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean 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 =3D > (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 > --- > 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 =3D > - (struct efi_driver_binding_extended_protocol *)this; > + struct efi_driver_binding_extended_protocol *bp =3D 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 =3D NULL; > - struct efi_driver_binding_extended_protocol *bp =3D > - (struct efi_driver_binding_extended_protocol *)this; > + struct efi_driver_binding_extended_protocol *bp =3D 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 =3D > - (struct efi_driver_binding_extended_protocol *)this; > + struct efi_driver_binding_extended_protocol *bp =3D 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 *dr= v) > } > bp->bp.image_handle =3D bp->bp.driver_binding_handle; > ret =3D efi_add_protocol(bp->bp.driver_binding_handle, > - &efi_guid_driver_binding_protocol, bp); > + &efi_guid_driver_binding_protocol, &bp->bp); > if (ret !=3D EFI_SUCCESS) { > efi_delete_handle(bp->bp.driver_binding_handle); > free(bp); >