From patchwork Tue May 31 06:31:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9143575 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 69F1D60761 for ; Tue, 31 May 2016 06:36:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DAB127DA9 for ; Tue, 31 May 2016 06:36:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5244827D17; Tue, 31 May 2016 06:36:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2D4727D17 for ; Tue, 31 May 2016 06:36:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755666AbcEaGcA (ORCPT ); Tue, 31 May 2016 02:32:00 -0400 Received: from mail-pa0-f66.google.com ([209.85.220.66]:34695 "EHLO mail-pa0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755632AbcEaGb5 (ORCPT ); Tue, 31 May 2016 02:31:57 -0400 Received: by mail-pa0-f66.google.com with SMTP id x1so7418923pav.1; Mon, 30 May 2016 23:31:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HEuEmImv8g67j3CbQJvNr/wGUM00PACsX/wa7x1UmQM=; b=Zc3wbq3ZsMrqung01jo5iVUmKwN8lasRC6Q5Viu6JW8c1W1rvMQDLYkuEntFKol0L6 dcg/9RZWiS1I5oyZoejXBD7GFGfm/tvZqTaQNYKpNBf6+NWJUDBY3vhruOiKUjF5RZhT 3BN2sSodHYVNVioqGKqW5k8wml+d2PXb7UX/6A5h7OXgQnN8D00K40RrjVBTFIAVx6U/ v/0uf1eNJ/Mfryh6bN6S3G24FHh7JFQd1UpQ3JtBbpDZd8TnhaVBv735LGXnuxRsFy1P oIPsTI6IG1/+74Wwq3BGZwXkMew7lmLNiNcRVmsQ8ISa7dU4fvFdCUJUXxzjGJrfk4VY zaCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HEuEmImv8g67j3CbQJvNr/wGUM00PACsX/wa7x1UmQM=; b=dKyhBIdazX982jcBr3+9WnPO0HZ/rCVhO4ANnNImfScew9P6l7rLgYVmnOmEqoTxdb lRdlv5ezcCWtuDBcdMTcbzH0EXLhxP18E97ov8zHSDEMMolGlMtXTbebBz7E4D4rHjyI pZ4i8smd+KFG2pAiYT32dDsrvecP4BoEN3KTL715kpDljfcTQ4EjkMEdtDtHB0ibepOc h0AIt7y2jlnTEprTpsQ17unzPxjb02CTmxovetXMkytBQS+gsqujkeJK2X5KWAIn45CB 9aJ6QCboZZdSVgW+/NV05SucfhQFrVsUubNApnWsj2yHHeEPNxLG1QCrVNgoqwBT3EbX vftA== X-Gm-Message-State: ALyK8tJgh5DmAnNIpvx+QLYkbwmb9y8RpaLgaSE998iFRv1m+pQ6NzK6VKlMgylSrEqnjg== X-Received: by 10.66.217.199 with SMTP id pa7mr573021pac.130.1464676316838; Mon, 30 May 2016 23:31:56 -0700 (PDT) Received: from localhost ([2601:b00:c501:3660:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id a19sm37247827pfc.57.2016.05.30.23.31.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2016 23:31:56 -0700 (PDT) From: Eduardo Valentin To: Rui Zhang Cc: Linux PM , LKML , Eduardo Valentin Subject: [PATCH 02/15] thermal: sysfs: lock tz while on access to mode properties Date: Mon, 30 May 2016 23:31:23 -0700 Message-Id: <1464676296-5610-3-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1464676296-5610-1-git-send-email-edubezval@gmail.com> References: <1464676296-5610-1-git-send-email-edubezval@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Serialized calls to tz.ops in user facing sysfs handler mode_show() and mode_store(). Cc: Zhang Rui Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- drivers/thermal/thermal_sysfs.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index ee983ca..1db2406 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -62,7 +62,9 @@ mode_show(struct device *dev, struct device_attribute *attr, char *buf) if (!tz->ops->get_mode) return -EPERM; + mutex_lock(&tz->lock); result = tz->ops->get_mode(tz, &mode); + mutex_unlock(&tz->lock); if (result) return result; @@ -75,17 +77,22 @@ mode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct thermal_zone_device *tz = to_thermal_zone(dev); + enum thermal_device_mode mode = THERMAL_DEVICE_DISABLED; int result; if (!tz->ops->set_mode) return -EPERM; if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); + mode = THERMAL_DEVICE_ENABLED; else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) - result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); + mode = THERMAL_DEVICE_DISABLED; else - result = -EINVAL; + return -EINVAL; + + mutex_lock(&tz->lock); + result = tz->ops->set_mode(tz, mode); + mutex_unlock(&tz->lock); if (result) return result;