Backports Archive on lore.kernel.org
 help / color / Atom feed
From: Hauke Mehrtens <hauke@hauke-m.de>
To: backports@vger.kernel.org
Cc: johannes@sipsolutions.net, Hauke Mehrtens <hauke@hauke-m.de>
Subject: [PATCH 2/7] backports: Add fallthrough attribute
Date: Mon, 22 Jun 2020 23:37:59 +0200
Message-ID: <20200622213804.26477-3-hauke@hauke-m.de> (raw)
In-Reply-To: <20200622213804.26477-1-hauke@hauke-m.de>

This adds the fallthrough attribute from Linux commit 294f69e662d1
("compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use")
This also adds the __has_attribute() define for older compilers like
GCC < 5.

linux/compiler_attributes.h needs to be included, this file was only
added in more recent kernel versions.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
 backport/backport-include/linux/compiler.h    |  2 ++
 .../linux/compiler_attributes.h               | 34 +++++++++++++++++++
 2 files changed, 36 insertions(+)
 create mode 100644 backport/backport-include/linux/compiler_attributes.h

diff --git a/backport/backport-include/linux/compiler.h b/backport/backport-include/linux/compiler.h
index 53c069df..51a6ec2c 100644
--- a/backport/backport-include/linux/compiler.h
+++ b/backport/backport-include/linux/compiler.h
@@ -2,6 +2,8 @@
 #define __BACKPORT_LINUX_COMPILER_H
 #include_next <linux/compiler.h>
 
+#include <linux/compiler_attributes.h>
+
 #ifndef __rcu
 #define __rcu
 #endif
diff --git a/backport/backport-include/linux/compiler_attributes.h b/backport/backport-include/linux/compiler_attributes.h
new file mode 100644
index 00000000..31ddc163
--- /dev/null
+++ b/backport/backport-include/linux/compiler_attributes.h
@@ -0,0 +1,34 @@
+#ifndef _BACKPORTS_LINUX_COMPILER_ATTRIBUTES_H
+#define _BACKPORTS_LINUX_COMPILER_ATTRIBUTES_H 1
+
+#if LINUX_VERSION_IS_GEQ(4,20,0)
+#include_next <linux/compiler_attributes.h>
+#endif
+
+#ifndef __has_attribute
+# define __has_attribute(x) __GCC4_has_attribute_##x
+#endif
+
+#ifndef __GCC4_has_attribute___fallthrough__
+# define __GCC4_has_attribute___fallthrough__         0
+#endif /* __GCC4_has_attribute___fallthrough__ */
+
+#ifndef fallthrough
+/*
+ * Add the pseudo keyword 'fallthrough' so case statement blocks
+ * must end with any of these keywords:
+ *   break;
+ *   fallthrough;
+ *   goto <label>;
+ *   return [expression];
+ *
+ *  gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes
+ */
+#if __has_attribute(__fallthrough__)
+# define fallthrough                    __attribute__((__fallthrough__))
+#else
+# define fallthrough                    do {} while (0)  /* fallthrough */
+#endif
+#endif /* fallthrough */
+
+#endif /* _BACKPORTS_LINUX_COMPILER_ATTRIBUTES_H */
-- 
2.20.1

--
To unsubscribe from this list: send the line "unsubscribe backports" in

  parent reply index

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-22 21:37 [PATCH 0/7] backports: Update to version 5.8-rc2 Hauke Mehrtens
2020-06-22 21:37 ` [PATCH 1/7] backports: patches: Refresh on kernel 5.8-rc2 Hauke Mehrtens
2020-06-22 21:37 ` Hauke Mehrtens [this message]
2020-06-22 21:38 ` [PATCH 3/7] backports: Add read_poll_timeout{_atomic}() Hauke Mehrtens
2020-06-22 21:38 ` [PATCH 4/7] backports: Add GUID_INIT() Hauke Mehrtens
2020-06-22 21:38 ` [PATCH 5/7] backports: Adapt acpi_evaluate_dsm() Hauke Mehrtens
2020-06-22 21:38 ` [PATCH 6/7] backports: dependencies: Add new mt76 driver options Hauke Mehrtens
2020-06-22 21:38 ` [PATCH 7/7] backports: Include missing header file for mt76 Hauke Mehrtens

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=20200622213804.26477-3-hauke@hauke-m.de \
    --to=hauke@hauke-m.de \
    --cc=backports@vger.kernel.org \
    --cc=johannes@sipsolutions.net \
    /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

Backports Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/backports/0 backports/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 backports backports/ https://lore.kernel.org/backports \
		backports@vger.kernel.org
	public-inbox-index backports

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.backports


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git