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 07C27C433F5 for ; Sat, 23 Oct 2021 23:31:09 +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 7FEA260E9C for ; Sat, 23 Oct 2021 23:31:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7FEA260E9C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.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 4AB588355C; Sun, 24 Oct 2021 01:30:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org 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; unprotected) header.d=chromium.org header.i=@chromium.org header.b="T6tUpV+v"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B24EE834F1; Sun, 24 Oct 2021 01:27:11 +0200 (CEST) Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) (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 9B9FC83521 for ; Sun, 24 Oct 2021 01:26:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oi1-x236.google.com with SMTP id o4so10009613oia.10 for ; Sat, 23 Oct 2021 16:26:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vtUMrD3ogwjBAEKtXTe+F5a6tG6uxjll7PuEeNmuuxQ=; b=T6tUpV+vBFLm1zbwTskyWw64Hktc0Yeuor3wv1vYCf2l8iDX23XpFrxGA2TGuY+1Ox KjAZMSQe8rr6Odnivxc2LhHgL42jkalV7LItNakMYI33735Qf5VR9G3MIzUxjqUVDJX7 hSqP8LDzlN0hsz0Lr8LlfZQ4ZIIm9Sd8gmo2g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vtUMrD3ogwjBAEKtXTe+F5a6tG6uxjll7PuEeNmuuxQ=; b=hVEVHE1mdk8lo/F6CjrvZj2rnHEiaaxWP5ZA0REYsVtXF5VGfo8Au8FSmtI1LfHwui 7qReXRIAQiH1AwUTZ7IQsDMjuRn3U/eF7IiEl8RYV1imqnkTT5881SQ+6OhJXqFFNGcX tGIUML32Xk9791oMgD81/7qXTWljkenlvtpCe3IzYVWUR/FY1K6i2r+TfDWUtBNgMJYY Tx6SPOv2PVLChk96Y74OpHNrZX92MJETJnBxCKHOaIw7FUes/jD0dTfKph5cyCS4YwWy +1GE8JFDSnlsm0PLy4Lmx0SF7q9ZxgnGUzAiZ4THQ5Qn/xU9Xl5jiDDmheGzNhvFsbKu WVNw== X-Gm-Message-State: AOAM531h5kM3yfI+gCo1UCHSWoZ3OEEow4SdQY0591xujBxx75Ij4p+Q cD7AzXGKYCI7HomcQZsDrUu/a7Ib4SaI6g== X-Google-Smtp-Source: ABdhPJwbakzjWZ/lxY7nb5FoiWawlS5j9YqmwZ+JpzHftOr4nDcp64Gsi2MlYZMzuEaYx1y3zt2xvA== X-Received: by 2002:aca:1712:: with SMTP id j18mr6039277oii.33.1635031616087; Sat, 23 Oct 2021 16:26:56 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id l24sm2253885oop.4.2021.10.23.16.26.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Oct 2021 16:26:55 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Michal Simek , Heinrich Schuchardt , Tom Rini , Ilias Apalodimas , Daniel Schwierzeck , Steffen Jaeckel , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Lukas Auer , Dennis Gilmore , Simon Glass , Marek Vasut , Pavel Herrmann Subject: [PATCH v2 11/41] dm: core: Fix handling of uclass pre_unbind method Date: Sat, 23 Oct 2021 17:26:05 -0600 Message-Id: <20211023232635.9195-10-sjg@chromium.org> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog In-Reply-To: <20211023232635.9195-1-sjg@chromium.org> References: <20211023232635.9195-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 This method is currently called after the platform data has been freed. But the pre_unbind() method may wish to access this, e.g. to free some data structures stored there. Split the unbinding of devices into two pieces, as is done with removal. This corrects the problem. Also tidy a code-style issue in device_remove() while we are here. Signed-off-by: Simon Glass --- (no changes since v1) drivers/core/device-remove.c | 9 +++++---- drivers/core/uclass.c | 8 +++++++- include/dm/uclass-internal.h | 14 +++++++++++++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index 11d3959d20f..69c50da44a9 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -95,6 +95,9 @@ int device_unbind(struct udevice *dev) if (ret) return log_msg_ret("child unbind", ret); + ret = uclass_pre_unbind_device(dev); + if (ret) + return log_msg_ret("uc", ret); if (dev_get_flags(dev) & DM_FLAG_ALLOC_PDATA) { free(dev_get_plat(dev)); dev_set_plat(dev, NULL); @@ -142,10 +145,8 @@ void device_free(struct udevice *dev) } if (dev->parent) { size = dev->parent->driver->per_child_auto; - if (!size) { - size = dev->parent->uclass->uc_drv-> - per_child_auto; - } + if (!size) + size = dev->parent->uclass->uc_drv->per_child_auto; if (size) { free(dev_get_parent_priv(dev)); dev_set_parent_priv(dev, NULL); diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index c5a50952fd0..2fede896bfb 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -682,7 +682,7 @@ err: } #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE) -int uclass_unbind_device(struct udevice *dev) +int uclass_pre_unbind_device(struct udevice *dev) { struct uclass *uc; int ret; @@ -694,7 +694,13 @@ int uclass_unbind_device(struct udevice *dev) return ret; } + return 0; +} + +int uclass_unbind_device(struct udevice *dev) +{ list_del(&dev->uclass_node); + return 0; } #endif diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h index 57c664c6daa..49808c5c856 100644 --- a/include/dm/uclass-internal.h +++ b/include/dm/uclass-internal.h @@ -243,6 +243,17 @@ int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent, */ int uclass_bind_device(struct udevice *dev); +#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE) +/** + * uclass_pre_unbind_device() - Prepare to deassociate device with a uclass + * + * Call any handled needed before uclass_unbind_device() is called + * + * @dev: Pointer to the device + * #return 0 on success, -ve on error + */ +int uclass_pre_unbind_device(struct udevice *dev); + /** * uclass_unbind_device() - Deassociate device with a uclass * @@ -251,9 +262,10 @@ int uclass_bind_device(struct udevice *dev); * @dev: Pointer to the device * #return 0 on success, -ve on error */ -#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE) int uclass_unbind_device(struct udevice *dev); + #else +static inline int uclass_pre_unbind_device(struct udevice *dev) { return 0; } static inline int uclass_unbind_device(struct udevice *dev) { return 0; } #endif -- 2.33.0.1079.g6e70778dc9-goog