From patchwork Tue Jul 31 07:27:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 1258401 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 282A3DF26F for ; Tue, 31 Jul 2012 07:27:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755639Ab2GaH1Y (ORCPT ); Tue, 31 Jul 2012 03:27:24 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:58486 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755628Ab2GaH1X (ORCPT ); Tue, 31 Jul 2012 03:27:23 -0400 Received: by pbbrp8 with SMTP id rp8so11227673pbb.19 for ; Tue, 31 Jul 2012 00:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=tUt50kWPjNTTGScN7F1MfkLA3fxnLGViNvZ/q2dFwnM=; b=nr6BW1zIO2wkVFQnME1AREi1Oj+Kpl7XX3ZBSOG4SOs9qT/McpQIDfHwH3fNTBNpi2 +T3jipzLRm1tFr1v+CwSVxAszGGJ71bx03jKM3rOnojYnUUgaMxbOKpY1lT4L83/a+J9 aS37Yzl1irh7TjgtaZNJWx0gcaa1gTsVGFzp5ZeBu0LALulSbdW+SNuNp2FE8NSnI2cc EIEGJEw9zhbfdmB+ZYNPyzYSJ2mU3ZA0W/n176mKBSQni7i134hcDCmdNs48sGRTJ4vU i4EFPRZZ3QdGqSzKSHAgNr1mrDhKui0njbAPNUc1lmsfb8OxPazg+Xu+BRrZYhhog8RD dX/A== Received: by 10.68.212.138 with SMTP id nk10mr41798242pbc.93.1343719642573; Tue, 31 Jul 2012 00:27:22 -0700 (PDT) Received: from mailhub.coreip.homeip.net (c-67-188-112-76.hsd1.ca.comcast.net. [67.188.112.76]) by mx.google.com with ESMTPS id jz4sm9582854pbc.17.2012.07.31.00.27.20 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 31 Jul 2012 00:27:21 -0700 (PDT) Date: Tue, 31 Jul 2012 00:27:17 -0700 From: Dmitry Torokhov To: Al Viro Cc: Baodong Chen , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] fixed a macro coding style issue Message-ID: <20120731072717.GC32327@core.coreip.homeip.net> References: <1343193656-2643-1-git-send-email-chenbdchenbd@gmail.com> <20120725053755.GA2100@core.coreip.homeip.net> <20120725061512.GB6481@ZenIV.linux.org.uk> <20120725063624.GA6546@core.coreip.homeip.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20120725063624.GA6546@core.coreip.homeip.net> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org On Tue, Jul 24, 2012 at 11:36:24PM -0700, Dmitry Torokhov wrote: > On Wed, Jul 25, 2012 at 07:15:12AM +0100, Al Viro wrote: > > On Tue, Jul 24, 2012 at 10:37:55PM -0700, Dmitry Torokhov wrote: > > > On Wed, Jul 25, 2012 at 01:20:56PM +0800, Baodong Chen wrote: > > > > Fixed a coding style issue in driver/input/input.c > > > > > > > > Signed-off-by: Baodong Chen > > > > --- > > > > drivers/input/input.c | 6 ++++-- > > > > 1 files changed, 4 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/drivers/input/input.c b/drivers/input/input.c > > > > index 8921c61..c96e983 100644 > > > > --- a/drivers/input/input.c > > > > +++ b/drivers/input/input.c > > > > @@ -845,11 +845,13 @@ int input_set_keycode(struct input_dev *dev, > > > > EXPORT_SYMBOL(input_set_keycode); > > > > > > > > #define MATCH_BIT(bit, max) \ > > > > + do { \ > > > > for (i = 0; i < BITS_TO_LONGS(max); i++) \ > > > > if ((id->bit[i] & dev->bit[i]) != id->bit[i]) \ > > > > break; \ > > > > - if (i != BITS_TO_LONGS(max)) \ > > > > - continue; > > > > + if (i != BITS_TO_LONGS(max)) \ > > > > + continue; \ > > > > + } while (0) > > > > > > This changes semantics. While current implementation of MATCH_BIT might > > > not be great style, it is not supposed to be used outside of > > > input_match_device(), and the replacement is completely broken. > > > > Replacement is certainly completely broken, but "might not be great style" > > is quite an understatement. Everything else aside, it's too obfuscated > > and ugly for anything outside of IOCCC and too verbose for IOCCC. > > > > Damnit, at least turn that into > > static inline int is_subset(unsigned long *bitmap1, unsigned long *bitmap2, size_t bits) > > { > > int i; > > for (i = BITS_TO_LONGS(bits); i; bitmap1++, bitmap2++, i--) > > if ((*bitmap1 & *bitmap2) != *bitmap1) > > return 0; > > return 1; > > } > > and just before your loop > > /* ignore ones that don't have bits required by id */ > > #define MATCH_BIT(array, bits) if (!is_subset(id->array, dev->array, bits)) continue; > > Hmm, we already have bitmap_subset(), I think we can simply use it. > > > with #undef MATCH_BIT right after the loop, to make it damn clean that it's local. > > And frankly, I'd consider expanding that variant and killing the macro off. > > Macros that affect control flow are vile and actively confusing for reader. > > I agree. In my defense it is quite old code... So how about the patch below? diff --git a/drivers/input/input.c b/drivers/input/input.c index 8921c61..768e46b 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -844,18 +844,10 @@ int input_set_keycode(struct input_dev *dev, } EXPORT_SYMBOL(input_set_keycode); -#define MATCH_BIT(bit, max) \ - for (i = 0; i < BITS_TO_LONGS(max); i++) \ - if ((id->bit[i] & dev->bit[i]) != id->bit[i]) \ - break; \ - if (i != BITS_TO_LONGS(max)) \ - continue; - static const struct input_device_id *input_match_device(struct input_handler *handler, struct input_dev *dev) { const struct input_device_id *id; - int i; for (id = handler->id_table; id->flags || id->driver_info; id++) { @@ -875,15 +867,32 @@ static const struct input_device_id *input_match_device(struct input_handler *ha if (id->version != dev->id.version) continue; - MATCH_BIT(evbit, EV_MAX); - MATCH_BIT(keybit, KEY_MAX); - MATCH_BIT(relbit, REL_MAX); - MATCH_BIT(absbit, ABS_MAX); - MATCH_BIT(mscbit, MSC_MAX); - MATCH_BIT(ledbit, LED_MAX); - MATCH_BIT(sndbit, SND_MAX); - MATCH_BIT(ffbit, FF_MAX); - MATCH_BIT(swbit, SW_MAX); + if (!bitmap_subset(id->evbit, dev->evbit, EV_MAX)) + continue; + + if (!bitmap_subset(id->keybit, dev->keybit, KEY_MAX)) + continue; + + if (!bitmap_subset(id->relbit, dev->relbit, REL_MAX)) + continue; + + if (!bitmap_subset(id->absbit, dev->absbit, ABS_MAX)) + continue; + + if (!bitmap_subset(id->mscbit, dev->mscbit, MSC_MAX)) + continue; + + if (!bitmap_subset(id->ledbit, dev->ledbit, LED_MAX)) + continue; + + if (!bitmap_subset(id->sndbit, dev->sndbit, SND_MAX)) + continue; + + if (!bitmap_subset(id->ffbit, dev->ffbit, FF_MAX)) + continue; + + if (!bitmap_subset(id->swbit, dev->swbit, SW_MAX)) + continue; if (!handler->match || handler->match(handler, dev)) return id;