From patchwork Thu Nov 15 10:22:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasilis Liaskovitis X-Patchwork-Id: 1748281 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 65701DF2AB for ; Thu, 15 Nov 2012 10:23:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2993149Ab2KOKXE (ORCPT ); Thu, 15 Nov 2012 05:23:04 -0500 Received: from mail-bk0-f46.google.com ([209.85.214.46]:37216 "EHLO mail-bk0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2993087Ab2KOKXB (ORCPT ); Thu, 15 Nov 2012 05:23:01 -0500 Received: by mail-bk0-f46.google.com with SMTP id q16so614372bkw.19 for ; Thu, 15 Nov 2012 02:23:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=PbzuIpPvV+KXhTY8QJUjhiRadxTHLGsXD5ss2U+0t1A=; b=NFVR2vsrirTi2Nh8BDni5v9RU9S5sBL10fK0C2z04MYiq4gXXYILCkm97mc3vZGD/w OfvpYqKw9eR1Q9Kedr+HOY7vuscQcc+m4drEXHy1Xat6NBRmE/jJlJHY4fBr3JDL0zT0 oLAQ4XfFvsvQVmpOGL3yo4yHkbAb751/t9IHIkNtjbNy0Aj6jn8rC3C2SoK0CAPo25Sp 4qvRkKI5TAOXKslGsDGC5yw1wc/nqr028Q9vc84tTGu1xtv1CvEfA4QBtnaCwXbJbujl OBT+aRwR10SBp3iTufe8RU2+fL1MwzxQz77SCeSFS2Kv925FHvzi1Fhd5z/Lj2rEOltV ywhA== Received: by 10.204.12.197 with SMTP id y5mr178145bky.77.1352974980513; Thu, 15 Nov 2012 02:23:00 -0800 (PST) Received: from dhcp-192-168-178-175.ri.profitbricks.localdomain ([62.217.45.26]) by mx.google.com with ESMTPS id k3sm2859450bku.13.2012.11.15.02.22.59 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 15 Nov 2012 02:22:59 -0800 (PST) From: Vasilis Liaskovitis To: linux-acpi@vger.kernel.org, isimatu.yasuaki@jp.fujitsu.com, wency@cn.fujitsu.com Cc: rjw@sisk.pl, lenb@kernel.org, toshi.kani@hp.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Vasilis Liaskovitis Subject: [RFC PATCH v2 2/3] acpi: Introduce prepare_remove operation in acpi_device_ops Date: Thu, 15 Nov 2012 11:22:49 +0100 Message-Id: <1352974970-6643-3-git-send-email-vasilis.liaskovitis@profitbricks.com> X-Mailer: git-send-email 1.7.9 In-Reply-To: <1352974970-6643-1-git-send-email-vasilis.liaskovitis@profitbricks.com> References: <1352974970-6643-1-git-send-email-vasilis.liaskovitis@profitbricks.com> X-Gm-Message-State: ALoCoQm9Tuc83J9m3u4pgK6zty7i30CK5dJhsEL/ctxaAEFRnnAMnIHyCwuNz8tndNv59GPGUzSZ Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org This function should be registered for devices that need to execute some non-driver core/acpi related action in order to be safely removed. If the removal preparation is successful, the acpi/driver core can continue with removing the device. Make acpi_bus_remove call the device-specific prepare_remove callback before removing the device. If prepare_remove fails, the removal is aborted. Also introduce acpi_device_prepare_remove which will call the device-specific prepare_remove callback on driver unbind or device reprobe requests from the device-driver core. Signed-off-by: Vasilis Liaskovitis --- drivers/acpi/scan.c | 21 ++++++++++++++++++++- include/acpi/acpi_bus.h | 2 ++ 2 files changed, 22 insertions(+), 1 deletions(-) diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 95ff1e8..725b012 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -582,11 +582,23 @@ static int acpi_device_remove(struct device * dev) return 0; } +static int acpi_device_prepare_remove(struct device *dev) +{ + struct acpi_device *acpi_dev = to_acpi_device(dev); + struct acpi_driver *acpi_drv = acpi_dev->driver; + int ret = 0; + + if (acpi_drv && acpi_drv->ops.prepare_remove) + ret = acpi_drv->ops.prepare_remove(acpi_dev); + return ret; +} + struct bus_type acpi_bus_type = { .name = "acpi", .match = acpi_bus_match, .probe = acpi_device_probe, .remove = acpi_device_remove, + .prepare_remove = acpi_device_prepare_remove, .uevent = acpi_device_uevent, }; @@ -1349,10 +1361,16 @@ static int acpi_device_set_context(struct acpi_device *device) static int acpi_bus_remove(struct acpi_device *dev, int rmdevice) { + int ret = 0; if (!dev) return -EINVAL; dev->removal_type = ACPI_BUS_REMOVAL_EJECT; + + if (dev->driver && dev->driver->ops.prepare_remove) + ret = dev->driver->ops.prepare_remove(dev); + if (ret) + return ret; device_release_driver(&dev->dev); if (!rmdevice) @@ -1671,7 +1689,8 @@ int acpi_bus_trim(struct acpi_device *start, int rmdevice) err = acpi_bus_remove(child, rmdevice); else err = acpi_bus_remove(child, 1); - + if (err) + return err; continue; } diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index e04ce7b..1a13c82 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -94,6 +94,7 @@ typedef int (*acpi_op_start) (struct acpi_device * device); typedef int (*acpi_op_bind) (struct acpi_device * device); typedef int (*acpi_op_unbind) (struct acpi_device * device); typedef void (*acpi_op_notify) (struct acpi_device * device, u32 event); +typedef int (*acpi_op_prepare_remove) (struct acpi_device *device); struct acpi_bus_ops { u32 acpi_op_add:1; @@ -107,6 +108,7 @@ struct acpi_device_ops { acpi_op_bind bind; acpi_op_unbind unbind; acpi_op_notify notify; + acpi_op_prepare_remove prepare_remove; }; #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */