From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753234AbbBXUvc (ORCPT ); Tue, 24 Feb 2015 15:51:32 -0500 Received: from bh-25.webhostbox.net ([208.91.199.152]:42230 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752413AbbBXUva (ORCPT ); Tue, 24 Feb 2015 15:51:30 -0500 Date: Tue, 24 Feb 2015 12:51:25 -0800 From: Guenter Roeck To: Phil Pokorny Cc: Bartosz Golaszewski , LKML , lm-sensors Subject: Re: [lm-sensors] [PATCH 1/4] kernel.h: add find_closest() macro Message-ID: <20150224205125.GB18025@roeck-us.net> References: <1424799734-2170-1-git-send-email-bgolaszewski@baylibre.com> <1424799734-2170-2-git-send-email-bgolaszewski@baylibre.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-CTCH-PVer: 0000001 X-CTCH-Spam: Unknown X-CTCH-VOD: Unknown X-CTCH-Flags: 0 X-CTCH-RefID: str=0001.0A020205.54ECE452.0068,ss=1,re=0.001,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 X-CTCH-Score: 0.001 X-CTCH-ScoreCust: 0.000 X-CTCH-Rules: C_4847, X-CTCH-SenderID: linux@roeck-us.net X-CTCH-SenderID-Flags: 0 X-CTCH-SenderID-TotalMessages: 3 X-CTCH-SenderID-TotalSpam: 0 X-CTCH-SenderID-TotalSuspected: 0 X-CTCH-SenderID-TotalConfirmed: 0 X-CTCH-SenderID-TotalBulk: 0 X-CTCH-SenderID-TotalVirus: 0 X-CTCH-SenderID-TotalRecipients: 0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: mailgid no entry from get_relayhosts_entry X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 24, 2015 at 12:33:06PM -0800, Phil Pokorny wrote: > On Tue, Feb 24, 2015 at 9:42 AM, Bartosz Golaszewski > wrote: > > > > Searching for the member of an array closest to 'x' is > > duplicated in several places. > > > > Add two macros that implement this algorithm for arrays > > sorted both in ascending and descending order. > > I don't see the point here. You're not saving any code because your > macros create functions at each invocation site. And your macro is > more complicated than the code it replaces because it has all the > syntactic cruft to make it adaptable to the different datatypes and > sort orders. > > Certainly it is easy to make an off by one mistake in a loop like this > so there might be some small value there, but I'm not sure the > complication is worth that savings for the small number of use points. > Particularly because you're not saving any code. > I think the lm85 conversion actually introduces a bug with such an off-by-one mistake. And if it doesn't, there is still a unexplained and not easy to understand '-1' in one of the calls to find_closest(). So the question is if the new code really improves the situation in that respect. Guenter