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 A0D58C433F5 for ; Mon, 27 Sep 2021 08:53:41 +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 A7EDA60F44 for ; Mon, 27 Sep 2021 08:53:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A7EDA60F44 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org 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 5FFE68323F; Mon, 27 Sep 2021 10:53:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="TezzuOhC"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0F3C583538; Mon, 27 Sep 2021 10:53:36 +0200 (CEST) Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3EC2D831BA for ; Mon, 27 Sep 2021 10:53:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pj1-x1035.google.com with SMTP id on12-20020a17090b1d0c00b001997c60aa29so11069415pjb.1 for ; Mon, 27 Sep 2021 01:53:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=Pf26/E6N0mpq/b+IWkAF86Hz3BXU+LKiH2QEopxOjCs=; b=TezzuOhCrUn4Q12oSKqe+8LoGPwtZ6EQJvYEQkKV8PSVMElMCRvT0F1vE1ajbnMBfr bhrowYqBl+TaAXmA69I84ZyWz36d+jnnJnne75wkZefA4M9jVYgM00vU1lOyzsq8GscX QZGjfQmdP90RymcUG6i6slatUES7SQ0ek+bEqyzaWhmgNE9tcqBYJzyvp78OwqwMoqsS JjCLur8/QRtDDowV7dzNpQcq2BHBNpz9wTLEsQj2Kp9fgFOyiE9WkchaDs3MtiPmY3S6 h2R9hg5toZJG7WWek9tW6D9/1mw1iUSk/Pdk4hTHd3E4gUAWBIWiXntfRIKUMrl8Sihu Hlpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=Pf26/E6N0mpq/b+IWkAF86Hz3BXU+LKiH2QEopxOjCs=; b=lg2OQJDN4tXHaIjxq/BJLhqXDQz5YzB11TMYOSABISV9DwOvglNQ+msNg1JNwzbiQd Al1pvlyXpD1vablBErVkVVrDs2g4YXV78JAbjskNK+zvB8nWkUHGL0M3VGnHQrw6n7Qt ODUCtwyc9qzK8hnVtDLZ2Nr5jePgbLmGBfZqKmzHQBnCWYMhzU4FVnAm9mIvLSoq0Awu u/AXhB0LYucag5iUQ7ig2D0qT9M2RoKljYDVzGAyNX3u0gPcaouVIBo84+A5UhhCMNXu NXRa3N3aT/fXMeaBn2J2wyLqRXBrn1GX4qcoWC4++FIu4tGvWgWTE9a0XQK6vjrdZ5Jy 89Og== X-Gm-Message-State: AOAM531duvKI+aI2HMKnOSlgN66lj/FM09jUJvCP6RCGdcQOBeQmQZXi 90Z0IKBwvDnkL+WFAnl3jsAdrg== X-Google-Smtp-Source: ABdhPJwWHVHQ8YzZVjwey/cLUIC3tDq0qb0QWVdmcSd11Aqo6jQZZeKw8PYgtnFJMvhG6K6nF32PeA== X-Received: by 2002:a17:90a:7348:: with SMTP id j8mr18427217pjs.104.1632732810318; Mon, 27 Sep 2021 01:53:30 -0700 (PDT) Received: from laputa (p6e421539.tkyea130.ap.so-net.ne.jp. [110.66.21.57]) by smtp.gmail.com with ESMTPSA id s25sm16145271pfm.138.2021.09.27.01.53.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 01:53:29 -0700 (PDT) Date: Mon, 27 Sep 2021 17:53:26 +0900 From: AKASHI Takahiro To: Heinrich Schuchardt Cc: u-boot@lists.denx.de, agraf@csgraf.de Subject: Re: [PATCH] efi_driver: fix a wrong cast Message-ID: <20210927085326.GA54445@laputa> Mail-Followup-To: AKASHI Takahiro , Heinrich Schuchardt , u-boot@lists.denx.de, agraf@csgraf.de References: <20210927043054.32727-1-takahiro.akashi@linaro.org> <30faf0b0-237d-02f3-9e35-6e746f1b3f52@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <30faf0b0-237d-02f3-9e35-6e746f1b3f52@gmx.de> 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 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 > > --- > > 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); > >