From patchwork Sat Jan 30 23:29:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael Wysocki X-Patchwork-Id: 75935 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o0UNTTnn006865 for ; Sat, 30 Jan 2010 23:29:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751484Ab0A3X3V (ORCPT ); Sat, 30 Jan 2010 18:29:21 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751949Ab0A3X3V (ORCPT ); Sat, 30 Jan 2010 18:29:21 -0500 Received: from ogre.sisk.pl ([217.79.144.158]:47636 "EHLO ogre.sisk.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751484Ab0A3X3U (ORCPT ); Sat, 30 Jan 2010 18:29:20 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by ogre.sisk.pl (Postfix) with ESMTP id 75BBE174E1B; Sun, 31 Jan 2010 00:15:34 +0100 (CET) Received: from ogre.sisk.pl ([127.0.0.1]) by localhost (ogre.sisk.pl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 23010-06; Sun, 31 Jan 2010 00:15:27 +0100 (CET) Received: from tosh.localnet (220-bem-13.acn.waw.pl [82.210.184.220]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ogre.sisk.pl (Postfix) with ESMTP id 4C20D174E0D; Sun, 31 Jan 2010 00:15:27 +0100 (CET) From: "Rafael J. Wysocki" To: ACPI Devel Maling List Subject: [RFC][RFT][PATCH] ACPI: Protection from suspending in the middle of EC transaction Date: Sun, 31 Jan 2010 00:29:48 +0100 User-Agent: KMail/1.12.4 (Linux/2.6.33-rc6-rjw; KDE/4.3.5; x86_64; ; ) Cc: Alexey Starikovskiy , Len Brown , pm list , Thomas Renninger , Maxim Levitsky , Matthew Garrett , LKML MIME-Version: 1.0 Message-Id: <201001310029.48717.rjw@sisk.pl> X-Virus-Scanned: amavisd-new at ogre.sisk.pl using MkS_Vir for Linux Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sat, 30 Jan 2010 23:29:29 +0000 (UTC) Index: linux-2.6/drivers/acpi/ec.c =================================================================== --- linux-2.6.orig/drivers/acpi/ec.c +++ linux-2.6/drivers/acpi/ec.c @@ -76,8 +76,9 @@ enum ec_command { enum { EC_FLAGS_QUERY_PENDING, /* Query is pending */ EC_FLAGS_GPE_STORM, /* GPE storm detected */ - EC_FLAGS_HANDLERS_INSTALLED /* Handlers for GPE and + EC_FLAGS_HANDLERS_INSTALLED, /* Handlers for GPE and * OpReg are installed */ + EC_FLAGS_SUSPENDED, /* Driver is suspended */ }; /* If we find an EC via the ECDT, we need to keep a ptr to its context */ @@ -291,6 +292,10 @@ static int acpi_ec_transaction(struct ac if (t->rdata) memset(t->rdata, 0, t->rlen); mutex_lock(&ec->lock); + if (test_bit(EC_FLAGS_SUSPENDED, &ec->flags)) { + status = -EBUSY; + goto unlock; + } if (ec->global_lock) { status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); if (ACPI_FAILURE(status)) { @@ -1059,16 +1064,26 @@ error: static int acpi_ec_suspend(struct acpi_device *device, pm_message_t state) { struct acpi_ec *ec = acpi_driver_data(device); + + mutex_lock(&ec->lock); + /* Prevent transactions from happening while suspended */ + set_bit(EC_FLAGS_SUSPENDED, &ec->flags); /* Stop using GPE */ acpi_disable_gpe(NULL, ec->gpe); + mutex_unlock(&ec->lock); return 0; } static int acpi_ec_resume(struct acpi_device *device) { struct acpi_ec *ec = acpi_driver_data(device); + + mutex_lock(&ec->lock); /* Enable use of GPE back */ acpi_enable_gpe(NULL, ec->gpe); + /* Allow transactions to happen again */ + set_bit(EC_FLAGS_SUSPENDED, &ec->flags); + mutex_unlock(&ec->lock); return 0; }