From patchwork Mon Aug 21 13:12:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Wunner X-Patchwork-Id: 803994 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xbYy169MBz9s7C for ; Mon, 21 Aug 2017 23:12:25 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753821AbdHUNMX (ORCPT ); Mon, 21 Aug 2017 09:12:23 -0400 Received: from mailout3.hostsharing.net ([176.9.242.54]:37017 "EHLO mailout3.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753110AbdHUNMW (ORCPT ); Mon, 21 Aug 2017 09:12:22 -0400 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mailout3.hostsharing.net (Postfix) with ESMTPS id 78485101E9E7D; Mon, 21 Aug 2017 15:12:21 +0200 (CEST) Received: from localhost (p4FC96673.dip0.t-ipconnect.de [79.201.102.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id 252D7603E121; Mon, 21 Aug 2017 15:12:21 +0200 (CEST) X-Mailbox-Line: From 5487a5f7d1a4be1bb13e7d1f392281d18c0e935e Mon Sep 17 00:00:00 2001 Message-Id: <5487a5f7d1a4be1bb13e7d1f392281d18c0e935e.1503319573.git.lukas@wunner.de> In-Reply-To: References: From: Lukas Wunner Date: Mon, 21 Aug 2017 15:12:00 +0200 Subject: [PATCH 1/4] bitops: Introduce assign_bit() To: Linus Walleij Cc: Mathias Duckeck , Phil Elwell , linux-gpio@vger.kernel.org, Bart Van Assche , Alasdair Kergon , Mike Snitzer Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org A common idiom is to assign a value to a bit with: if (value) set_bit(nr, addr); else clear_bit(nr, addr); Likewise common is the one-line expression variant: value ? set_bit(nr, addr) : clear_bit(nr, addr); Commit 9a8ac3ae682e ("dm mpath: cleanup QUEUE_IF_NO_PATH bit manipulation by introducing assign_bit()") introduced assign_bit() to the md subsystem for brevity. Make it available to others, in particular gpiolib and the upcoming driver for Maxim MAX3191x industrial serializer chips. Cc: Bart Van Assche Cc: Alasdair Kergon Cc: Mike Snitzer Signed-off-by: Lukas Wunner --- drivers/md/dm-mpath.c | 8 -------- include/linux/bitops.h | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c index 0e8ab5bb3575..c79c113b7e7d 100644 --- a/drivers/md/dm-mpath.c +++ b/drivers/md/dm-mpath.c @@ -638,14 +638,6 @@ static void process_queued_bios(struct work_struct *work) blk_finish_plug(&plug); } -static void assign_bit(bool value, long nr, unsigned long *addr) -{ - if (value) - set_bit(nr, addr); - else - clear_bit(nr, addr); -} - /* * If we run out of usable paths, should we queue I/O or error it? */ diff --git a/include/linux/bitops.h b/include/linux/bitops.h index a83c822c35c2..097af36887c0 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -226,6 +226,30 @@ static inline unsigned long __ffs64(u64 word) return __ffs((unsigned long)word); } +/** + * assign_bit - Assign value to a bit in memory + * @value: the value to assign + * @nr: the bit to set + * @addr: the address to start counting from + */ +static __always_inline void assign_bit(bool value, long nr, + volatile unsigned long *addr) +{ + if (value) + set_bit(nr, addr); + else + clear_bit(nr, addr); +} + +static __always_inline void __assign_bit(bool value, long nr, + volatile unsigned long *addr) +{ + if (value) + __set_bit(nr, addr); + else + __clear_bit(nr, addr); +} + #ifdef __KERNEL__ #ifndef set_mask_bits