From patchwork Thu Nov 29 11:27:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 202710 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 2F7652C0094 for ; Thu, 29 Nov 2012 22:28:14 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753626Ab2K2L2L (ORCPT ); Thu, 29 Nov 2012 06:28:11 -0500 Received: from mail-pa0-f46.google.com ([209.85.220.46]:38129 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752760Ab2K2L2K (ORCPT ); Thu, 29 Nov 2012 06:28:10 -0500 Received: by mail-pa0-f46.google.com with SMTP id bh2so7553682pad.19 for ; Thu, 29 Nov 2012 03:28:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=g8eDr3nt1spCCGfGoK7V4398feUxzYzoUC2WnQpBORw=; b=vfQIrJlD8Mt5jdrZxKLUAOntFJZnAiiBBKvwWAmrxC8ghK/g0UIL1w26fYi22UuSop g250wxLRnP0xfwEdvqnnWBTyp/JkYkFmpCf2z2+SJBcI1ZJmpibnJt4mPTDaUbsnBabA OPrS6IXPIhwj147c8FJnIDPzszNj5fCq4R0PCz+YSOj9blxZei1PJ3FbZ9BVTFqlW9fa akirdhlnSXEB9BrJkNm8O9iM8dssFbCjms5ByT5ZMWpiraMZ69IrLvtHxNVv2eH8q50Y 5mSsNFqf/3+xVgPe1qJ7DegBO67SHzxdKf5PwcabQLCwXUxBB1iVhUq5oS2QqIiLCpao DXgg== Received: by 10.68.234.98 with SMTP id ud2mr67595337pbc.136.1354188489970; Thu, 29 Nov 2012 03:28:09 -0800 (PST) Received: from localhost.localdomain (p1120-ipbf2201hodogaya.kanagawa.ocn.ne.jp. [123.220.186.120]) by mx.google.com with ESMTPS id r6sm938881pax.24.2012.11.29.03.28.08 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 29 Nov 2012 03:28:09 -0800 (PST) From: Akinobu Mita To: netdev@vger.kernel.org Cc: Akinobu Mita , Karsten Keil Subject: [PATCH] mISDN: improve bitops usage Date: Thu, 29 Nov 2012 20:27:45 +0900 Message-Id: <1354188465-29012-1-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.7.11.7 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This improves bitops usages in several points: - Convert u64 to a proper bitmap declaration. This enables to remove superfluous typecasting from 'u64' to 'unsigned long *'. - Convert superfluous atomic bitops to non atomic bitops. The bitmap is allocated on the stack and it is not accessed by any other threads, so using atomic bitops is not necessary. - Use find_next_zero_bit and find_next_zero_bit instead of calling test_bit() for each bit. Signed-off-by: Akinobu Mita Cc: Karsten Keil Cc: netdev@vger.kernel.org --- drivers/isdn/mISDN/tei.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/isdn/mISDN/tei.c b/drivers/isdn/mISDN/tei.c index be88728..592f597 100644 --- a/drivers/isdn/mISDN/tei.c +++ b/drivers/isdn/mISDN/tei.c @@ -250,7 +250,7 @@ tei_debug(struct FsmInst *fi, char *fmt, ...) static int get_free_id(struct manager *mgr) { - u64 ids = 0; + DECLARE_BITMAP(ids, 64) = { [0 ... BITS_TO_LONGS(64) - 1] = 0 }; int i; struct layer2 *l2; @@ -261,11 +261,11 @@ get_free_id(struct manager *mgr) __func__); return -EBUSY; } - test_and_set_bit(l2->ch.nr, (u_long *)&ids); + __set_bit(l2->ch.nr, ids); } - for (i = 1; i < 64; i++) - if (!test_bit(i, (u_long *)&ids)) - return i; + i = find_next_zero_bit(ids, 64, 1); + if (i < 64) + return i; printk(KERN_WARNING "%s: more as 63 layer2 for one device\n", __func__); return -EBUSY; @@ -274,7 +274,7 @@ get_free_id(struct manager *mgr) static int get_free_tei(struct manager *mgr) { - u64 ids = 0; + DECLARE_BITMAP(ids, 64) = { [0 ... BITS_TO_LONGS(64) - 1] = 0 }; int i; struct layer2 *l2; @@ -288,11 +288,11 @@ get_free_tei(struct manager *mgr) continue; i -= 64; - test_and_set_bit(i, (u_long *)&ids); + __set_bit(i, ids); } - for (i = 0; i < 64; i++) - if (!test_bit(i, (u_long *)&ids)) - return i + 64; + i = find_first_zero_bit(ids, 64); + if (i < 64) + return i + 64; printk(KERN_WARNING "%s: more as 63 dynamic tei for one device\n", __func__); return -1;