From patchwork Sun Mar 29 22:28:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Hutchings X-Patchwork-Id: 6117881 Return-Path: X-Original-To: patchwork-linux-fbdev@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 86F0B9F349 for ; Sun, 29 Mar 2015 22:28:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4A57E20279 for ; Sun, 29 Mar 2015 22:28:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D960B20263 for ; Sun, 29 Mar 2015 22:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752601AbbC2W2l (ORCPT ); Sun, 29 Mar 2015 18:28:41 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:43537 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752455AbbC2W2k (ORCPT ); Sun, 29 Mar 2015 18:28:40 -0400 Received: from deadeye.wl.decadent.org.uk ([192.168.4.249] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1YcLh8-0005sW-MG; Sun, 29 Mar 2015 23:28:38 +0100 Received: from ben by deadeye with local (Exim 4.84) (envelope-from ) id 1YcLh3-0007vu-F7; Sun, 29 Mar 2015 23:28:33 +0100 Message-ID: <1427668108.32382.106.camel@decadent.org.uk> Subject: [PATCH] sisfb: Replace creative use of the ternary operator From: Ben Hutchings To: Thomas Winischhofer Cc: linux-fbdev@vger.kernel.org Date: Sun, 29 Mar 2015 23:28:28 +0100 X-Mailer: Evolution 3.12.9-1+b1 Mime-Version: 1.0 X-SA-Exim-Connect-IP: 192.168.4.249 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, T_TVD_MIME_EPI, 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 GETBITSTR() and related macros are defined in such a way that two of the macro arguments must be pairs of integers joined with a ':', selected between by prepending '1?' or '0?'. This is rather clever but not very readable. Redefine the macros and change the users so that each integer is a separate argument. While we're at it, add a BUILD_BUG_ON_ZERO() to check that the redundant first part of the 'to' argument is consistent with the other arguments. Signed-off-by: Ben Hutchings --- drivers/video/fbdev/sis/init.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/drivers/video/fbdev/sis/init.c b/drivers/video/fbdev/sis/init.c index dfe3eb7..d0c2e72 100644 --- a/drivers/video/fbdev/sis/init.c +++ b/drivers/video/fbdev/sis/init.c @@ -3320,11 +3320,9 @@ SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo) return true; } -#ifndef GETBITSTR -#define GENBITSMASK(mask) GENMASK(1?mask,0?mask) -#define GETBITS(var,mask) (((var) & GENBITSMASK(mask)) >> (0?mask)) -#define GETBITSTR(val,from,to) ((GETBITS(val,from)) << (0?to)) -#endif +#define GETBITSTR(val, fromhigh, fromlow, tohigh, tolow) \ + (((((val) & GENMASK(fromhigh, fromlow)) >> (fromlow)) << (tolow)) + \ + BUILD_BUG_ON_ZERO((fromhigh) - (fromlow) != (tohigh) - (tolow))) void SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth) @@ -3363,23 +3361,23 @@ SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth) SiS_Pr->CCRT1CRTC[12] = (SiS_Pr->CVBlankEnd - 1) & 0xFF; /* CR16 */ SiS_Pr->CCRT1CRTC[13] = /* SRA */ - GETBITSTR((SiS_Pr->CVTotal -2), 10:10, 0:0) | - GETBITSTR((SiS_Pr->CVDisplay -1), 10:10, 1:1) | - GETBITSTR((SiS_Pr->CVBlankStart-1), 10:10, 2:2) | - GETBITSTR((SiS_Pr->CVSyncStart -x), 10:10, 3:3) | - GETBITSTR((SiS_Pr->CVBlankEnd -1), 8:8, 4:4) | - GETBITSTR((SiS_Pr->CVSyncEnd ), 4:4, 5:5) ; + GETBITSTR((SiS_Pr->CVTotal -2), 10, 10, 0, 0) | + GETBITSTR((SiS_Pr->CVDisplay -1), 10, 10, 1, 1) | + GETBITSTR((SiS_Pr->CVBlankStart-1), 10, 10, 2, 2) | + GETBITSTR((SiS_Pr->CVSyncStart -x), 10, 10, 3, 3) | + GETBITSTR((SiS_Pr->CVBlankEnd -1), 8, 8, 4, 4) | + GETBITSTR((SiS_Pr->CVSyncEnd ), 4, 4, 5, 5) ; SiS_Pr->CCRT1CRTC[14] = /* SRB */ - GETBITSTR((SiS_Pr->CHTotal >> 3) - 5, 9:8, 1:0) | - GETBITSTR((SiS_Pr->CHDisplay >> 3) - 1, 9:8, 3:2) | - GETBITSTR((SiS_Pr->CHBlankStart >> 3) - 1, 9:8, 5:4) | - GETBITSTR((SiS_Pr->CHSyncStart >> 3) + 3, 9:8, 7:6) ; + GETBITSTR((SiS_Pr->CHTotal >> 3) - 5, 9, 8, 1, 0) | + GETBITSTR((SiS_Pr->CHDisplay >> 3) - 1, 9, 8, 3, 2) | + GETBITSTR((SiS_Pr->CHBlankStart >> 3) - 1, 9, 8, 5, 4) | + GETBITSTR((SiS_Pr->CHSyncStart >> 3) + 3, 9, 8, 7, 6) ; SiS_Pr->CCRT1CRTC[15] = /* SRC */ - GETBITSTR((SiS_Pr->CHBlankEnd >> 3) - 1, 7:6, 1:0) | - GETBITSTR((SiS_Pr->CHSyncEnd >> 3) + 3, 5:5, 2:2) ; + GETBITSTR((SiS_Pr->CHBlankEnd >> 3) - 1, 7, 6, 1, 0) | + GETBITSTR((SiS_Pr->CHSyncEnd >> 3) + 3, 5, 5, 2, 2) ; } void