mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 3/4] bitops: implement assign_bit()
Date: Mon,  7 Nov 2022 15:45:23 +0100	[thread overview]
Message-ID: <20221107144524.489471-4-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20221107144524.489471-1-s.hauer@pengutronix.de>

assign_bit() is a useful shortcut to if (foo) set_bit(); else clear_bit();

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/linux/bitops.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 84161e43a3..eb5ff37f2f 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -194,6 +194,20 @@ static inline unsigned long __ffs64(u64 word)
 	return __ffs((unsigned long)word);
 }
 
+/**
+ * assign_bit - Assign value to a bit in memory
+ * @nr: the bit to set
+ * @addr: the address to start counting from
+ * @value: the value to assign
+ */
+static inline void assign_bit(long nr, volatile unsigned long *addr, bool value)
+{
+	if (value)
+		set_bit(nr, addr);
+	else
+		clear_bit(nr, addr);
+}
+
 #ifdef __KERNEL__
 
 #ifndef set_mask_bits
-- 
2.30.2




  parent reply	other threads:[~2022-11-07 15:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-07 14:45 [PATCH 0/4] gpio: Add gpio latch driver Sascha Hauer
2022-11-07 14:45 ` [PATCH 1/4] bitmap: Implement bitmap_*zalloc() Sascha Hauer
2022-11-07 14:45 ` [PATCH 2/4] bitops: include linux/types.h Sascha Hauer
2022-11-07 14:45 ` Sascha Hauer [this message]
2022-11-07 14:45 ` [PATCH 4/4] gpio: Add gpio latch driver Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221107144524.489471-4-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --subject='Re: [PATCH 3/4] bitops: implement assign_bit()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox