From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754635AbcCZXxK (ORCPT ); Sat, 26 Mar 2016 19:53:10 -0400 Received: from smtprelay0083.hostedemail.com ([216.40.44.83]:42449 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754404AbcCZXxI (ORCPT ); Sat, 26 Mar 2016 19:53:08 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::,RULES_HIT:41:355:379:541:599:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2828:3138:3139:3140:3141:3142:3352:3622:3865:3866:3868:3873:3874:4321:5007:10004:10400:10848:11026:11473:11658:11914:12043:12296:12438:12517:12519:12740:13069:13311:13357:13439:13894:14659:14721:21080:30012:30054:30056:30064:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: feet06_3811b72998031 X-Filterd-Recvd-Size: 2274 Message-ID: <1459036383.23450.12.camel@perches.com> Subject: Re: [PATCH] intel_menlow: reduce code duplication From: Joe Perches To: Rasmus Villemoes , Sujith Thomas , Darren Hart Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Date: Sat, 26 Mar 2016 16:53:03 -0700 In-Reply-To: <1459028427-4053-1-git-send-email-linux@rasmusvillemoes.dk> References: <1459028427-4053-1-git-send-email-linux@rasmusvillemoes.dk> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.18.5.2-0ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 2016-03-26 at 22:40 +0100, Rasmus Villemoes wrote: > aux0_show and aux1_show consists of almost identical code. Pull that > into a common helper and make them thin wrappers. Similarly for > _store. Seems sensible, thanks > diff --git 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)); While not something you've done differently than the existing code, perhaps this would be more common without the ternary operator like: result = sensor_get_auxtrip(attr->handle, idx, &value); if (result < 0) return result; return sprintf(buf, "%lu", DECI_KELVIN_TO_CELSIUS(value));