]> www.infradead.org Git - mtd-utils.git/commitdiff
Add no-return attribute to usage() style functions
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Thu, 21 Sep 2017 11:36:42 +0000 (13:36 +0200)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Thu, 2 Nov 2017 00:33:32 +0000 (01:33 +0100)
A common pattern in command line processing is having a usage()
function that prints out how to use the command line options and
then terminates.

The function is typically used inside a switch block for command
line options like `-h' or unknown options. In a lot of places, the
break keyword is omitted, because the function exits anyway. However,
this triggers gcc warnings about implicit fall-through.

Rather than adding a phony "/* fall-through */" this patch flags the
usage() style function with a gcc attribute, indicating that they do
not return and removes further superfluous break statements.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
13 files changed:
include/common.h
misc-utils/flash_unlock.c
misc-utils/flashcp.c
misc-utils/mtd_debug.c
nand-utils/nandtest.c
nand-utils/nftl_format.c
tests/mtd-tests/flash_readtest.c
tests/mtd-tests/flash_speed.c
tests/mtd-tests/flash_stress.c
tests/mtd-tests/flash_torture.c
tests/mtd-tests/nandbiterrs.c
tests/mtd-tests/nandpagetest.c
tests/mtd-tests/nandsubpagetest.c

index d6092571779706410e28fac018b942bae85f9395..2ce5d2252e8787c1d7260cc3954c50f6627bd45c 100644 (file)
@@ -129,6 +129,13 @@ extern "C" {
        fprintf(stderr, "%s: warning!: " fmt "\n", PROGRAM_NAME, ##__VA_ARGS__); \
 } while(0)
 
+/* for tagging functions that always exit */
+#if defined(__GNUC__) || defined(__clang__)
+       #define NORETURN __attribute__((noreturn))
+#else
+       #define NORETURN
+#endif
+
 /**
  * prompt the user for confirmation
  */
index 5a3aac532053c75b018efaf440590e03b807cabd..fbbfa5177c94c9b12a4f0bee803f11b66f36e201 100644 (file)
@@ -36,7 +36,7 @@ static const char *flash_msg[] = {
        [ REQUEST_ISLOCKED ]    = "check lock status",
 };
 
-static void usage(int status)
+static NORETURN void usage(int status)
 {
        fprintf(status ? stderr : stdout,
                "Utility to lock, unlock, or check the lock status of the flash.\n"
@@ -88,7 +88,6 @@ static void process_args(int argc, char *argv[])
                switch (c) {
                case 'h':
                        usage(EXIT_SUCCESS);
-                       break;
                case 'i':
                        req = REQUEST_ISLOCKED;
                        req_set++;
@@ -106,7 +105,6 @@ static void process_args(int argc, char *argv[])
                        exit(0);
                default:
                        usage(EXIT_FAILURE);
-                       break;
                }
        }
 
index a35e6fca9d8da0be4920adfcfa0d44e235179366..0718733d0c2be17a2ee8203738a3468edcc69add 100644 (file)
@@ -81,7 +81,7 @@ static void log_printf (int level,const char *fmt, ...)
        fflush (fp);
 }
 
-static void showusage(bool error)
+static NORETURN void showusage(bool error)
 {
        int level = error ? LOG_ERROR : LOG_NORMAL;
 
index 90f5d524771a73d363815721d41923d1324765b9..d90a96832cfe27e18f73ab362fab401ce84c0882 100644 (file)
@@ -339,7 +339,7 @@ static int showinfo(int fd)
        return 0;
 }
 
-static void showusage(void)
+static NORETURN void showusage(void)
 {
        fprintf(stderr, "usage: %1$s info <device>\n"
                        "       %1$s read <device> <offset> <len> <dest-filename>\n"
index d5c736930429764eff4bd418c4a34d48599d6888..06dec25c7f95f62825b986487f25a8aabd60888b 100644 (file)
@@ -17,7 +17,7 @@
 #include "mtd/mtd-user.h"
 #include "common.h"
 
-static void usage(int status)
+static NORETURN void usage(int status)
 {
        fprintf(status ? stderr : stdout,
                "usage: %s [OPTIONS] <device>\n\n"
@@ -184,14 +184,12 @@ int main(int argc, char **argv)
                switch (c) {
                case 'h':
                        usage(EXIT_SUCCESS);
-                       break;
                case 'V':
                        common_print_version();
                        exit(EXIT_SUCCESS);
                        break;
                case '?':
                        usage(EXIT_FAILURE);
-                       break;
 
                case 'm':
                        markbad = 1;
index ec87604ad87977f944f8daf8ba2a07b6c2b14e11..c8b8b5065845d635d201331da149b23673acee51 100644 (file)
@@ -198,7 +198,7 @@ static int checkbbt(void)
        return (0);
 }
 
-static void usage(int rc)
+static NORETURN void usage(int rc)
 {
        fprintf(stderr, "Usage: %s [-ib] <mtddevice> [<start offset> [<size>]]\n", PROGRAM_NAME);
        exit(rc);
@@ -250,13 +250,11 @@ int main(int argc, char **argv)
                        case 'h':
                        case '?':
                                usage(EXIT_SUCCESS);
-                               break;
                        case 'V':
                                display_version();
                                break;
                        default:
                                usage(EXIT_FAILURE);
-                               break;
                }
        }
 
index bc6874a0cf693a90e4d348e6cfc00b13c835b995..c5fabc94dab9117c25b3eff065edad0160e0420c 100644 (file)
@@ -54,7 +54,7 @@ static const struct option options[] = {
        { NULL, 0, NULL, 0 },
 };
 
-static void usage(int status)
+static NORETURN void usage(int status)
 {
        fputs(
        "Usage: "PROGRAM_NAME" [OPTIONS] <device>\n\n"
index d5cedba732e7202725a596a19cb08782c4a08a2e..00582698c7f52cd385a148b22c8b2df2d814296c 100644 (file)
@@ -60,7 +60,7 @@ static const struct option options[] = {
        { NULL, 0, NULL, 0 },
 };
 
-static void usage(int status)
+static NORETURN void usage(int status)
 {
        fputs(
        "Usage: "PROGRAM_NAME" [OPTIONS] <device>\n\n"
@@ -100,7 +100,6 @@ static void process_options(int argc, char **argv)
                switch (c) {
                case 'h':
                        usage(EXIT_SUCCESS);
-                       break;
                case 'b':
                        if (peb >= 0)
                                goto failmulti;
index f50c6646ddf93c7da1db05cc74a516a7df03f387..249d8cbc6c4cbd5e445b69a38d4fdd7a6a5c5334 100644 (file)
@@ -63,7 +63,7 @@ static const struct option options[] = {
        { NULL, 0, NULL, 0 },
 };
 
-static void usage(int status)
+static NORETURN void usage(int status)
 {
        fputs(
        "Usage: "PROGRAM_NAME" [OPTIONS] <device>\n\n"
index 21cedf4b07e4a54a1478eea2076a2c38814139d3..5aad8e0964fd31a420b7f22765ca6c7597876784 100644 (file)
@@ -67,7 +67,7 @@ static void sighandler(int sig)
                flags &= ~RUN_FOREVER;
 }
 
-static void usage(int status)
+static NORETURN void usage(int status)
 {
        fputs(
        "Usage: "PROGRAM_NAME" [OPTIONS] <device>\n\n"
index 200fe1c5f5b274fb96a61499002912d68677b19b..ef987dce7ca4b9045b89fd988dc784c2991156ec 100644 (file)
@@ -85,7 +85,7 @@ static const struct option options[] = {
        { NULL, 0, NULL, 0 },
 };
 
-static void usage(int status)
+static NORETURN void usage(int status)
 {
        fputs(
        "Usage: "PROGRAM_NAME" [OPTIONS] <device>\n\n"
index 86c900598f2bf98e4f4fc5df5034ef2df7274ba9..2b16cc928eae155a5564135afc33cd40d780b83b 100644 (file)
@@ -58,7 +58,7 @@ static const struct option options[] = {
        { NULL, 0, NULL, 0 },
 };
 
-static void usage(int status)
+static NORETURN void usage(int status)
 {
        fputs(
        "Usage: "PROGRAM_NAME" [OPTIONS] <device>\n\n"
index 04f6c8cf083e6cb12e48fcfd93c53370e8d5d013..cd7e4e8b324694fdf47743e0cbbe91dd04d631c0 100644 (file)
@@ -57,7 +57,7 @@ static const struct option options[] = {
        { NULL, 0, NULL, 0 },
 };
 
-static void usage(int status)
+static NORETURN void usage(int status)
 {
        fputs(
        "Usage: "PROGRAM_NAME" [OPTIONS] <device>\n\n"