From patchwork Fri Aug 2 02:48:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 2837497 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D278DBF535 for ; Fri, 2 Aug 2013 02:49:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 912A020412 for ; Fri, 2 Aug 2013 02:49:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 88B672040F for ; Fri, 2 Aug 2013 02:49:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754754Ab3HBCsv (ORCPT ); Thu, 1 Aug 2013 22:48:51 -0400 Received: from mail-ob0-f172.google.com ([209.85.214.172]:48615 "EHLO mail-ob0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753892Ab3HBCsu (ORCPT ); Thu, 1 Aug 2013 22:48:50 -0400 Received: by mail-ob0-f172.google.com with SMTP id er7so238878obc.17 for ; Thu, 01 Aug 2013 19:48:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=XoY9PTUkxySlNNyUfsrgPHuudeqNn0O7f5Xq+VK6ngM=; b=RNuInGiGXs8KEvfxicFTVhCebg/3cXJZQuVGVH7YCUOZTCNjk4QSPnIsJQOTdGGuVa /WrRg+YmJh/EibB8qGXPerB0Mo3nNrpKXcX7e6JXCyfbA6oa/Ig2UfQFeZ/9q/HfdJvx nZ+sx94EiVvmUsmnTACp2QbS1QrpnpBVjtnhUITepfq6uBMUdWxkt99FmMm0k3W3FjWr N/KSp9xpQOWbhjeI+KZLUIOh4NECffIVP5bTbJNyUOx1Y+BQzhHzz9/Tq5vCbQpL2Az+ J+6M7mkrjuYxWG/srDqrK2ol0q4yBaxdG4GtanCOH7pRNAilEtEvDvJdrDLk8B7nKBIE v8YA== MIME-Version: 1.0 X-Received: by 10.50.40.35 with SMTP id u3mr61873igk.23.1375411729731; Thu, 01 Aug 2013 19:48:49 -0700 (PDT) Received: by 10.64.34.203 with HTTP; Thu, 1 Aug 2013 19:48:49 -0700 (PDT) In-Reply-To: <1888947.F5IBMfDKlY@vostro.rjw.lan> References: <1888947.F5IBMfDKlY@vostro.rjw.lan> Date: Fri, 2 Aug 2013 10:48:49 +0800 Message-ID: Subject: Re: [PATCH] ACPI: Do not fail acpi_bind_one() if device is already bound correctly From: Lan Tianyu To: "Rafael J. Wysocki" Cc: ACPI Devel Maling List , LKML , Bjorn Helgaas , Toshi Kani Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 2013/8/2 Rafael J. Wysocki : > From: Rafael J. Wysocki > > Modify acpi_bind_one() so that it doesn't fail if the device > represented by its first argument has already been bound to the > given ACPI handle (second argument), because that is not a good > enough reason for returning an error code. > > Signed-off-by: Rafael J. Wysocki > --- > drivers/acpi/glue.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) > > Index: linux-pm/drivers/acpi/glue.c > =================================================================== > --- linux-pm.orig/drivers/acpi/glue.c > +++ linux-pm/drivers/acpi/glue.c > @@ -143,7 +143,10 @@ int acpi_bind_one(struct device *dev, ac > list_for_each_entry(pn, &acpi_dev->physical_node_list, node) > if (pn->dev == dev) { > dev_warn(dev, "Already associated with ACPI node\n"); > - goto err_free; > + if (ACPI_HANDLE(dev) == handle) > + retval = 0; > + > + goto out_free; > } > > /* allocate physical node id according to physical_node_id_bitmap */ > @@ -152,7 +155,7 @@ int acpi_bind_one(struct device *dev, ac > ACPI_MAX_PHYSICAL_NODE); > if (physical_node->node_id >= ACPI_MAX_PHYSICAL_NODE) { > retval = -ENOSPC; > - goto err_free; > + goto out_free; > } > > set_bit(physical_node->node_id, acpi_dev->physical_node_id_bitmap); > @@ -185,10 +188,14 @@ int acpi_bind_one(struct device *dev, ac > put_device(dev); > return retval; > > - err_free: > + out_free: > mutex_unlock(&acpi_dev->physical_node_lock); > kfree(physical_node); > - goto err; > + if (retval) > + goto err; > + > + put_device(dev); > + return 0; > } > EXPORT_SYMBOL_GPL(acpi_bind_one); Hi Rafael: How about the following change? > > > -- > To unsubscribe from this list: send the line "unsubscribe linux-acpi" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html Reviewed-by: Lan Tianyu diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c index f70cc45..35f375e 100644 --- a/drivers/acpi/glue.c +++ b/drivers/acpi/glue.c @@ -183,19 +183,15 @@ int acpi_bind_one(struct device *dev, acpi_handle handle) return 0; - err: - ACPI_HANDLE_SET(dev, NULL); - put_device(dev); - return retval; - out_free: mutex_unlock(&acpi_dev->physical_node_lock); kfree(physical_node); - if (retval) - goto err; + err: + if (retval) + ACPI_HANDLE_SET(dev, NULL); put_device(dev); - return 0; + return retval; } EXPORT_SYMBOL_GPL(acpi_bind_one); --------------- When I reviewed this patch, found the dev's acpi handle always is set to NULL if there is error. This seems make no sense for the case that the handle has been set to dev before binding. For this case, the acpi handle has been found before binding. Actually, the device driver could control any resources under ACPI node even if the binding failed. So adding one flag to differentiate it. diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c index 35f375e..c868e51 100644 --- a/drivers/acpi/glue.c +++ b/drivers/acpi/glue.c @@ -113,6 +113,7 @@ int acpi_bind_one(struct device *dev, acpi_handle handle) acpi_status status; struct acpi_device_physical_node *physical_node, *pn; char physical_node_name[sizeof(PHYSICAL_NODE_STRING) + 2]; + bool has_handle = false; int retval = -EINVAL; if (ACPI_HANDLE(dev)) { @@ -121,6 +122,7 @@ int acpi_bind_one(struct device *dev, acpi_handle handle) return -EINVAL; } else { handle = ACPI_HANDLE(dev); + has_handle = true; } } if (!handle) @@ -188,7 +190,7 @@ int acpi_bind_one(struct device *dev, acpi_handle handle) kfree(physical_node); err: - if (retval) + if (retval && !has_handle) ACPI_HANDLE_SET(dev, NULL); put_device(dev); return retval;