From patchwork Sat Mar 26 21:40:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 8674991 Return-Path: X-Original-To: patchwork-platform-driver-x86@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C50AB9F326 for ; Sat, 26 Mar 2016 21:40:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C88C020260 for ; Sat, 26 Mar 2016 21:40:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BE9BE20219 for ; Sat, 26 Mar 2016 21:40:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754155AbcCZVkf (ORCPT ); Sat, 26 Mar 2016 17:40:35 -0400 Received: from mail-wm0-f42.google.com ([74.125.82.42]:36064 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754124AbcCZVke (ORCPT ); Sat, 26 Mar 2016 17:40:34 -0400 Received: by mail-wm0-f42.google.com with SMTP id l71so2568385wmg.1 for ; Sat, 26 Mar 2016 14:40:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id; bh=Utxgu1OX45szaFubqedM0jgytlsDRkdA9eWQRY+fukw=; b=Uh18lp4BHV35EpCuqLwEpNpOxlgq6B17IpURAjGzigmut0OvANREsp7vyZ3CF45/m2 z+CWY3MOXS7fwgQTcgtjYsq1Pe85ystmHrS0/yJilEA7shMqjbSfQME7Tab3zF6apchz jzHPSS1jHUKxWvThX7bgsuG0j45Oa83VogM38= 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; bh=Utxgu1OX45szaFubqedM0jgytlsDRkdA9eWQRY+fukw=; b=lrKtz5vpw4sB2/qN9vHogzkc0DOk/bmrxJfFv/R6JCYKQqAPHCjGlmZoAUzWDMmMoM 8rgdlzIXMgQBYTC9AgrfSx02sAJI8Tkp/H221X2TfKzIfk402fcaAjE4ep0d6MhReOlo JWIclYR668A/S5hZdpxnsShkuuXtkXZTGAIX0REH7asC74K1gmSmKzqRe5ywc2iStmIg Oeq/w9FcyFWGZxTHyI0LwcBxYAM3BtQiOnGLKcd5+Lji3+ufvUweWDubwK/EysSFqilD d+PYi//abn2WJzQ6HcIKDtRZu5Pvg9WIZCofBmWUCPxll7xzsgEouKtekHRmhoq3ioCf rttA== X-Gm-Message-State: AD7BkJLauwAHQ+bPe2wRswy4cFGVZ8FW9G8GF6eZbYXQGgDGol6FX7kkvzKjOXGciI+DKg== X-Received: by 10.194.63.75 with SMTP id e11mr21039401wjs.79.1459028433166; Sat, 26 Mar 2016 14:40:33 -0700 (PDT) Received: from localhost.localdomain (lvps87-230-87-209.dedicated.hosteurope.de. [87.230.87.209]) by smtp.gmail.com with ESMTPSA id lh1sm17617286wjb.20.2016.03.26.14.40.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 26 Mar 2016 14:40:32 -0700 (PDT) From: Rasmus Villemoes To: Sujith Thomas , Darren Hart Cc: Rasmus Villemoes , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] intel_menlow: reduce code duplication Date: Sat, 26 Mar 2016 22:40:26 +0100 Message-Id: <1459028427-4053-1-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.1.4 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham 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 aux0_show and aux1_show consists of almost identical code. Pull that into a common helper and make them thin wrappers. Similarly for _store. Signed-off-by: Rasmus Villemoes --- drivers/platform/x86/intel_menlow.c | 48 ++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/drivers/platform/x86/intel_menlow.c b/drivers/platform/x86/intel_menlow.c index 0a919d81662c..ae3a2a831533 100644 --- a/drivers/platform/x86/intel_menlow.c +++ b/drivers/platform/x86/intel_menlow.c @@ -306,33 +306,32 @@ static int sensor_set_auxtrip(acpi_handle handle, int index, int value) #define to_intel_menlow_attr(_attr) \ container_of(_attr, struct intel_menlow_attribute, attr) -static ssize_t aux0_show(struct device *dev, - struct device_attribute *dev_attr, char *buf) +static ssize_t aux_show(struct device *dev, struct device_attribute *dev_attr, + char *buf, int idx) { struct intel_menlow_attribute *attr = to_intel_menlow_attr(dev_attr); unsigned long long value; int result; - result = sensor_get_auxtrip(attr->handle, 0, &value); + result = sensor_get_auxtrip(attr->handle, idx, &value); return result ? result : sprintf(buf, "%lu", DECI_KELVIN_TO_CELSIUS(value)); } -static ssize_t aux1_show(struct device *dev, +static ssize_t aux0_show(struct device *dev, struct device_attribute *dev_attr, char *buf) { - struct intel_menlow_attribute *attr = to_intel_menlow_attr(dev_attr); - unsigned long long value; - int result; - - result = sensor_get_auxtrip(attr->handle, 1, &value); + return aux_show(dev, dev_attr, buf, 0); +} - return result ? result : sprintf(buf, "%lu", DECI_KELVIN_TO_CELSIUS(value)); +static ssize_t aux1_show(struct device *dev, + struct device_attribute *dev_attr, char *buf) +{ + return aux_show(dev, dev_attr, buf, 1); } -static ssize_t aux0_store(struct device *dev, - struct device_attribute *dev_attr, - const char *buf, size_t count) +static ssize_t aux_store(struct device *dev, struct device_attribute *dev_attr, + const char *buf, size_t count, int idx) { struct intel_menlow_attribute *attr = to_intel_menlow_attr(dev_attr); int value; @@ -345,27 +344,22 @@ static ssize_t aux0_store(struct device *dev, if (value < 0) return -EINVAL; - result = sensor_set_auxtrip(attr->handle, 0, CELSIUS_TO_DECI_KELVIN(value)); + result = sensor_set_auxtrip(attr->handle, idx, CELSIUS_TO_DECI_KELVIN(value)); return result ? result : count; } -static ssize_t aux1_store(struct device *dev, +static ssize_t aux0_store(struct device *dev, struct device_attribute *dev_attr, const char *buf, size_t count) { - struct intel_menlow_attribute *attr = to_intel_menlow_attr(dev_attr); - int value; - int result; - - /*Sanity check; should be a positive integer */ - if (!sscanf(buf, "%d", &value)) - return -EINVAL; - - if (value < 0) - return -EINVAL; + return aux_store(dev, dev_attr, buf, count, 0); +} - result = sensor_set_auxtrip(attr->handle, 1, CELSIUS_TO_DECI_KELVIN(value)); - return result ? result : count; +static ssize_t aux1_store(struct device *dev, + struct device_attribute *dev_attr, + const char *buf, size_t count) +{ + return aux_store(dev, dev_attr, buf, count, 1); } /* BIOS can enable/disable the thermal user application in dabney platform */