diff options
44 files changed, 719 insertions, 305 deletions
diff --git a/Documentation/devicetree/bindings/mtd/partition.txt b/Documentation/devicetree/bindings/mtd/partition.txt index ab21ff25bb..4288a82437 100644 --- a/Documentation/devicetree/bindings/mtd/partition.txt +++ b/Documentation/devicetree/bindings/mtd/partition.txt @@ -5,6 +5,11 @@ In addition to the upstream binding, another property is added: Optional properties: - partuuid : The partition UUID for this partition. +Additionally, barebox also supports partitioning the eMMC boot partitions if +the partition table node is named appropriately: +- partitions : user partition +- boot0-partitions : boot0 partition +- boot1-partitions : boot1 partition Examples: @@ -19,3 +24,16 @@ flash@0 { }; }; }; + +emmc@1 { + boot0-partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + barebox@0 { + label = "barebox"; + reg = <0x0 0x300000>; + }; + }; +}; @@ -10,4 +10,12 @@ config SRCARCH source "arch/$SRCARCH/Kconfig" +source common/Kconfig +source commands/Kconfig +source net/Kconfig +source drivers/Kconfig +source fs/Kconfig +source lib/Kconfig +source crypto/Kconfig +source firmware/Kconfig source "scripts/Kconfig" diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 3b486f7b8b..cdc22efdeb 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -412,12 +412,3 @@ config ARM_PSCI_DEBUG Only use for debugging. endmenu - -source common/Kconfig -source commands/Kconfig -source net/Kconfig -source drivers/Kconfig -source fs/Kconfig -source lib/Kconfig -source crypto/Kconfig -source firmware/Kconfig diff --git a/arch/arm/boards/phytec-som-am335x/board.c b/arch/arm/boards/phytec-som-am335x/board.c index 8c24f2b332..441d56348c 100644 --- a/arch/arm/boards/phytec-som-am335x/board.c +++ b/arch/arm/boards/phytec-som-am335x/board.c @@ -73,7 +73,7 @@ static const char *eth_names[ETH_COUNT] = {"mac0", "mac1"}; static int physom_devices_init(void) { struct state *state; - u8 mac[6]; + uint8_t mac[6]; int state_ret; int state_i; @@ -130,7 +130,7 @@ static int physom_devices_init(void) for (state_i = 0; state_i < 2; state_i++) { state_ret = state_read_mac(state, eth_names[state_i], &mac[0]); - if (state_ret == 6) + if (!state_ret && is_valid_ether_addr(&mac[0])) eth_register_ethaddr(state_i, mac); } } diff --git a/arch/arm/boards/phytec-som-imx6/board.c b/arch/arm/boards/phytec-som-imx6/board.c index 4079bc9de1..38a2ef641e 100644 --- a/arch/arm/boards/phytec-som-imx6/board.c +++ b/arch/arm/boards/phytec-som-imx6/board.c @@ -99,8 +99,17 @@ static unsigned int get_module_rev(void) static int ksz8081_phy_fixup(struct phy_device *phydev) { + /* + * 0x8100 default + * 0x0080 RMII 50 MHz clock mode + * 0x0010 LED Mode 1 + */ phy_write(phydev, 0x1f, 0x8190); - phy_write(phydev, 0x16, 0x202); + /* + * 0x0002 Override strap-in for RMII mode + * This should be default but after reset we occasionally read 0x0001 + */ + phy_write(phydev, 0x16, 0x2); return 0; } diff --git a/arch/arm/boards/raspberry-pi/rpi-common.c b/arch/arm/boards/raspberry-pi/rpi-common.c index b7ce0ad425..650b26ce7d 100644 --- a/arch/arm/boards/raspberry-pi/rpi-common.c +++ b/arch/arm/boards/raspberry-pi/rpi-common.c @@ -176,6 +176,7 @@ const struct rpi_model rpi_models_new_scheme[] = { RPI_MODEL(BCM2836_BOARD_REV_2_B, "2 Model B", rpi_b_plus_init), RPI_MODEL(BCM2837_BOARD_REV_3_B, "3 Model B", rpi_b_plus_init), RPI_MODEL(BCM2835_BOARD_REV_ZERO, "Zero", rpi_b_plus_init), + RPI_MODEL(BCM2835_BOARD_REV_ZERO_W, "Zero W", rpi_b_plus_init), }; static int rpi_board_rev = 0; diff --git a/arch/arm/lib32/unwind.c b/arch/arm/lib32/unwind.c index fd4b0b22cb..02fae3c253 100644 --- a/arch/arm/lib32/unwind.c +++ b/arch/arm/lib32/unwind.c @@ -62,9 +62,9 @@ static void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame) { #ifdef CONFIG_KALLSYMS - printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from); + pr_warning("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from); #else - printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from); + pr_warning("Function entered at [<%08lx>] from [<%08lx>]\n", where, from); #endif } diff --git a/arch/arm/mach-bcm283x/include/mach/mbox.h b/arch/arm/mach-bcm283x/include/mach/mbox.h index 0d1ac074e3..76b573f85f 100644 --- a/arch/arm/mach-bcm283x/include/mach/mbox.h +++ b/arch/arm/mach-bcm283x/include/mach/mbox.h @@ -133,6 +133,8 @@ struct bcm2835_mbox_tag_hdr { #define BCM2837_BOARD_REV_3_B 0x8 /* Zero */ #define BCM2835_BOARD_REV_ZERO 0x9 +/* Zero W */ +#define BCM2835_BOARD_REV_ZERO_W 0xc /* * 0x2..0xf from: diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig index 6233614e19..c9b5512c0a 100644 --- a/arch/blackfin/Kconfig +++ b/arch/blackfin/Kconfig @@ -64,11 +64,3 @@ config BFIN_BOOT_FLASH16 blackfin is strapped to boot from 16bit wide flash via boot ROM endchoice - -source common/Kconfig -source commands/Kconfig -source net/Kconfig -source drivers/Kconfig -source fs/Kconfig -source lib/Kconfig -source crypto/Kconfig diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index 524375a81a..7c40991cab 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -353,11 +353,3 @@ config MIPS_OPTIMIZED_STRING_FUNCTIONS increase your binary size. endmenu - -source common/Kconfig -source commands/Kconfig -source net/Kconfig -source drivers/Kconfig -source fs/Kconfig -source lib/Kconfig -source crypto/Kconfig diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig index 199540ba74..c7c13a464b 100644 --- a/arch/nios2/Kconfig +++ b/arch/nios2/Kconfig @@ -27,11 +27,3 @@ config EARLY_PRINTF bool "Enable early printf functions" endmenu - -source common/Kconfig -source commands/Kconfig -source net/Kconfig -source drivers/Kconfig -source fs/Kconfig -source lib/Kconfig -source crypto/Kconfig diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig index 2a8abf0ff8..32d23029d8 100644 --- a/arch/openrisc/Kconfig +++ b/arch/openrisc/Kconfig @@ -27,11 +27,3 @@ config GENERIC select OPENRISC endchoice - -source common/Kconfig -source commands/Kconfig -source net/Kconfig -source drivers/Kconfig -source fs/Kconfig -source lib/Kconfig -source crypto/Kconfig diff --git a/arch/ppc/Kconfig b/arch/ppc/Kconfig index 97e6c00689..7a45ced7cd 100644 --- a/arch/ppc/Kconfig +++ b/arch/ppc/Kconfig @@ -20,10 +20,3 @@ endchoice source arch/ppc/mach-mpc5xxx/Kconfig source arch/ppc/mach-mpc85xx/Kconfig -source common/Kconfig -source commands/Kconfig -source net/Kconfig -source drivers/Kconfig -source fs/Kconfig -source lib/Kconfig -source crypto/Kconfig diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig index 3f1cefb837..5227cb624f 100644 --- a/arch/sandbox/Kconfig +++ b/arch/sandbox/Kconfig @@ -15,11 +15,3 @@ config LINUX config ARCH_LINUX bool - -source common/Kconfig -source commands/Kconfig -source net/Kconfig -source drivers/Kconfig -source fs/Kconfig -source lib/Kconfig -source crypto/Kconfig diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 52ccf4894f..3f91585d02 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -97,11 +97,3 @@ endchoice source arch/x86/boot/Kconfig source arch/x86/mach-i386/Kconfig - -source common/Kconfig -source commands/Kconfig -source net/Kconfig -source drivers/Kconfig -source fs/Kconfig -source lib/Kconfig -source crypto/Kconfig diff --git a/common/ddr_spd.c b/common/ddr_spd.c index ec343ef5a5..7e2945ed96 100644 --- a/common/ddr_spd.c +++ b/common/ddr_spd.c @@ -166,7 +166,6 @@ static int ddr2_sdram_ctime(uint8_t byte) void ddr_spd_print(uint8_t *record) { int highestCAS = 0; - int cas[256]; int i, i_i, k, x, y; int ddrclk, tbits, pcclk; int trcd, trp, tras; @@ -199,7 +198,6 @@ void ddr_spd_print(uint8_t *record) for (i_i = 2; i_i < 7; i_i++) { if (s->cas_lat & 1 << i_i) { highestCAS = i_i; - cas[highestCAS]++; } } diff --git a/common/hush.c b/common/hush.c index 792b61ac9a..d2f9cc70f5 100644 --- a/common/hush.c +++ b/common/hush.c @@ -106,6 +106,9 @@ * General Public License for more details. * */ + +#define pr_fmt(fmt) "hush: " fmt + #include <malloc.h> /* malloc, free, realloc*/ #include <xfuncs.h> #include <linux/ctype.h> /* isalpha, isdigit */ @@ -263,8 +266,13 @@ struct in_str { #define b_getch(input) ((input)->get(input)) #define b_peek(input) ((input)->peek(input)) +#ifdef HUSH_DEBUG +#define hush_debug(fmt, arg...) debug(fmt, ##arg) +#else +#define hush_debug(fmt, arg...) +#endif -#define final_printf debug +#define final_printf hush_debug static void syntax(void) { @@ -349,7 +357,7 @@ static int b_check_space(o_string *o, int len) static int b_addchr(o_string *o, int ch) { - debug("%s: %c %d %p\n", __func__, ch, o->length, o); + hush_debug("%s: %c %d %p\n", __func__, ch, o->length, o); if (b_check_space(o, 1)) return B_NOSPAC; @@ -504,7 +512,7 @@ static int file_get(struct in_str *i) if (i->p && *i->p) ch = *i->p++; - debug("%s: got a %d\n", __func__, ch); + hush_debug("%s: got a %d\n", __func__, ch); return ch; } @@ -756,7 +764,7 @@ static int run_pipe_real(struct p_context *ctx, struct pipe *pi) child = &pi->progs[0]; if (child->group) { - debug("non-subshell grouping\n"); + hush_debug("non-subshell grouping\n"); rcode = run_list_real(ctx, child->group); return rcode; @@ -782,7 +790,7 @@ static int run_pipe_real(struct p_context *ctx, struct pipe *pi) char *name, *value; name = xstrdup(child->argv[i]); - debug("Local environment set: %s\n", name); + hush_debug("Local environment set: %s\n", name); value = strchr(name, '='); if (value) @@ -888,7 +896,7 @@ static int run_list_real(struct p_context *ctx, struct pipe *pi) } } rmode = pi->r_mode; - debug("rmode=%d if_code=%d next_if_code=%d skip_more=%d\n", + hush_debug("rmode=%d if_code=%d next_if_code=%d skip_more=%d\n", rmode, if_code, next_if_code, skip_more_in_this_rmode); if (rmode == skip_more_in_this_rmode && flag_skip) { if (pi->followup == PIPE_SEQ) @@ -959,7 +967,7 @@ static int run_list_real(struct p_context *ctx, struct pipe *pi) continue; rcode = run_pipe_real(ctx, pi); - debug("run_pipe_real returned %d\n",rcode); + hush_debug("run_pipe_real returned %d\n",rcode); if (rcode < -1) { last_return_code = -rcode - 2; @@ -1050,16 +1058,16 @@ static int xglob(o_string *dest, int flags, glob_t *pglob, int glob_needed) if (dest->nonnull) { /* bash man page calls this an "explicit" null */ gr = fake_glob(dest->data, flags, NULL, pglob); - debug("globhack returned %d\n",gr); + hush_debug("globhack returned %d\n",gr); } else { return 0; } } else if (glob_needed) { gr = do_glob(dest->data, flags, NULL, pglob); - debug("glob returned %d\n",gr); + hush_debug("glob returned %d\n",gr); } else { gr = fake_glob(dest->data, flags, NULL, pglob); - debug("globhack returned %d\n",gr); + hush_debug("globhack returned %d\n",gr); } if (gr != 0) { /* GLOB_ABORTED ? */ error_msg("glob(3) error %d",gr); @@ -1210,12 +1218,12 @@ static int reserved_word(o_string *dest, struct p_context *ctx) if (strcmp(dest->data, r->literal)) continue; - debug("found reserved word %s, code %d\n",r->literal,r->code); + hush_debug("found reserved word %s, code %d\n",r->literal,r->code); if (r->flag & FLAG_START) { struct p_context *new = xmalloc(sizeof(struct p_context)); - debug("push stack\n"); + hush_debug("push stack\n"); if (ctx->w == RES_IN || ctx->w == RES_FOR) { syntax(); @@ -1241,7 +1249,7 @@ static int reserved_word(o_string *dest, struct p_context *ctx) if (ctx->old_flag & FLAG_END) { struct p_context *old; - debug("pop stack\n"); + hush_debug("pop stack\n"); done_pipe(ctx,PIPE_SEQ); old = ctx->stack; @@ -1266,9 +1274,9 @@ static int done_word(o_string *dest, struct p_context *ctx) glob_t *glob_target; int gr, flags = GLOB_NOCHECK; - debug("%s: %s %p\n", __func__, dest->data, child); + hush_debug("%s: %s %p\n", __func__, dest->data, child); if (dest->length == 0 && !dest->nonnull) { - debug(" true null, ignored\n"); + hush_debug(" true null, ignored\n"); return 0; } if (child->group) { @@ -1276,7 +1284,7 @@ static int done_word(o_string *dest, struct p_context *ctx) return 1; /* syntax error, groups and arglists don't mix */ } if (!child->argv && (ctx->type & FLAG_PARSE_SEMICOLON)) { - debug("checking %s for reserved-ness\n",dest->data); + hush_debug("checking %s for reserved-ness\n",dest->data); if (reserved_word(dest,ctx)) return ctx->w == RES_SNTX; } @@ -1315,13 +1323,13 @@ static int done_command(struct p_context *ctx) struct child_prog *prog = ctx->child; if (prog && prog->group == NULL && prog->argv == NULL) { - debug("%s: skipping null command\n", __func__); + hush_debug("%s: skipping null command\n", __func__); return 0; } else if (prog) { pi->num_progs++; - debug("%s: num_progs incremented to %d\n", __func__, pi->num_progs); + hush_debug("%s: num_progs incremented to %d\n", __func__, pi->num_progs); } else { - debug("%s: initializing\n", __func__); + hush_debug("%s: initializing\n", __func__); } pi->progs = xrealloc(pi->progs, sizeof(*pi->progs) * (pi->num_progs + 1)); @@ -1344,7 +1352,7 @@ static int done_pipe(struct p_context *ctx, pipe_style type) done_command(ctx); /* implicit closure of previous command */ - debug("%s: type %d\n", __func__, type); + hush_debug("%s: type %d\n", __func__, type); ctx->pipe->followup = type; ctx->pipe->r_mode = ctx->w; @@ -1405,7 +1413,7 @@ static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *i int advance = 0, i; int ch = input->peek(input); /* first character after the $ */ - debug("%s: ch=%c\n", __func__, ch); + hush_debug("%s: ch=%c\n", __func__, ch); if (isalpha(ch)) { b_addchr(dest, SPECIAL_VAR_SYMBOL); @@ -1490,7 +1498,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx, * A single-quote triggers a bypass of the main loop until its mate is * found. When recursing, quote state is passed in via dest->quote. */ - debug("%s: end_trigger=%d\n", __func__, end_trigger); + hush_debug("%s: end_trigger=%d\n", __func__, end_trigger); while ((ch = b_getch(input)) != EOF) { m = map[ch]; @@ -1498,7 +1506,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx, return 1; next = (ch == '\n') ? 0 : b_peek(input); - debug("%s: ch=%c (%d) m=%d quote=%d - %c\n", + hush_debug("%s: ch=%c (%d) m=%d quote=%d - %c\n", __func__, ch >= ' ' ? ch : '.', ch, m, dest->quote, ctx->stack == NULL ? '*' : '.'); @@ -1519,7 +1527,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx, } if (ch == end_trigger && !dest->quote && ctx->w==RES_NONE) { - debug("%s: leaving (triggered)\n", __func__); + hush_debug("%s: leaving (triggered)\n", __func__); return 0; } @@ -1608,7 +1616,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx, * that is, we were really supposed to get end_trigger, and never got * one before the EOF. Can't use the standard "syntax error" return code, * so that parse_stream_outer can distinguish the EOF and exit smoothly. */ - debug("%s: leaving (EOF)\n", __func__); + hush_debug("%s: leaving (EOF)\n", __func__); if (end_trigger != '\0') return -1; diff --git a/common/memory_display.c b/common/memory_display.c index ea91985e5d..cd0eadf88d 100644 --- a/common/memory_display.c +++ b/common/memory_display.c @@ -4,10 +4,21 @@ #define DISP_LINE_LEN 16 -int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size, int swab) + +int __pr_memory_display(int level, const void *addr, loff_t offs, unsigned nbytes, + int size, int swab, const char *fmt, ...) { unsigned long linebytes, i; unsigned char *cp; + unsigned char line[sizeof("00000000: 0000 0000 0000 0000 0000 0000 0000 0000 ................")]; + struct va_format vaf; + int ret; + va_list args; + + va_start(args, fmt); + + vaf.fmt = fmt; + vaf.va = &args; /* Print the lines. * @@ -20,9 +31,9 @@ int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size, int uint32_t *uip = (uint32_t *)linebuf; uint16_t *usp = (uint16_t *)linebuf; uint8_t *ucp = (uint8_t *)linebuf; - unsigned count = 52; + unsigned char *pos = line; - printf("%08llx:", offs); + pos += sprintf(pos, "%08llx:", offs); linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes; for (i = 0; i < linebytes; i += size) { @@ -34,9 +45,9 @@ int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size, int res = __swab64(res); if (data_abort_unmask()) { res = 0xffffffffffffffffULL; - count -= printf(" xxxxxxxxxxxxxxxx"); + pos += sprintf(pos, " xxxxxxxxxxxxxxxx"); } else { - count -= printf(" %016llx", res); + pos += sprintf(pos, " %016llx", res); } *ullp++ = res; } else if (size == 4) { @@ -47,9 +58,9 @@ int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size, int res = __swab32(res); if (data_abort_unmask()) { res = 0xffffffff; - count -= printf(" xxxxxxxx"); + pos += sprintf(pos, " xxxxxxxx"); } else { - count -= printf(" %08x", res); + pos += sprintf(pos, " %08x", res); } *uip++ = res; } else if (size == 2) { @@ -58,22 +69,26 @@ int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size, int res = *((uint16_t *)addr); if (swab) res = __swab16(res); + if (i > 1 && i % 8 == 0) + pos += sprintf(pos, " "); if (data_abort_unmask()) { res = 0xffff; - count -= printf(" xxxx"); + pos += sprintf(pos, " xxxx"); } else { - count -= printf(" %04x", res); + pos += sprintf(pos, " %04x", res); } *usp++ = res; } else { uint8_t res; data_abort_mask(); res = *((uint8_t *)addr); + if (i > 1 && i % 8 == 0) + pos += sprintf(pos, " "); if (data_abort_unmask()) { res = 0xff; - count -= printf(" xx"); + pos += sprintf(pos, " xx"); } else { - count -= printf(" %02x", res); + pos += sprintf(pos, " %02x", res); } *ucp++ = res; } @@ -81,23 +96,40 @@ int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size, int offs += size; } - while (count--) - putchar(' '); + pos += sprintf(pos, "%*s", 61 - (pos - line), ""); cp = linebuf; for (i = 0; i < linebytes; i++) { if ((*cp < 0x20) || (*cp > 0x7e)) - putchar('.'); + sprintf(pos, "."); else - printf("%c", *cp); + sprintf(pos, "%c", *cp); + pos++; cp++; } - putchar('\n'); + if (level >= MSG_EMERG) + pr_print(level, "%pV%s\n", &vaf, line); + else + printf("%s\n", line); + nbytes -= linebytes; - if (ctrlc()) - return -EINTR; + if (ctrlc()) { + ret = -EINTR; + goto out; + } + } while (nbytes > 0); - return 0; + va_end(args); + ret = 0; +out: + + return ret; } + +int memory_display(const void *addr, loff_t offs, unsigned nbytes, + int size, int swab) +{ + return pr_memory_display(-1, addr, offs, nbytes, size, swab); +}
\ No newline at end of file diff --git a/common/misc.c b/common/misc.c index 665f72be7e..66aba534fc 100644 --- a/common/misc.c +++ b/common/misc.c @@ -67,11 +67,11 @@ const char *strerror(int errnum) case ETIMEDOUT : str = "Connection timed out"; break; case EPROBE_DEFER : str = "Requested probe deferral"; break; case ELOOP : str = "Too many symbolic links encountered"; break; + case ENODATA : str = "No data available"; break; #if 0 /* These are probably not needed */ case ENOTBLK : str = "Block device required"; break; case EFBIG : str = "File too large"; break; case EBADSLT : str = "Invalid slot"; break; - case ENODATA : str = "No data available"; break; case ETIME : str = "Timer expired"; break; case ENONET : str = "Machine is not on the network"; break; case EADV : str = "Advertise error"; break; diff --git a/common/parser.c b/common/parser.c index 6136dbf36f..397d268da1 100644 --- a/common/parser.c +++ b/common/parser.c @@ -70,7 +70,7 @@ static void process_macros (const char *input, char *output) /* 3 = waiting for ''' */ char __maybe_unused *output_start = output; - pr_debug("[PROCESS_MACROS] INPUT len %d: \"%s\"\n", strlen (input), + pr_debug("[PROCESS_MACROS] INPUT len %zu: \"%s\"\n", strlen (input), input); prev = '\0'; /* previous character */ @@ -158,7 +158,7 @@ static void process_macros (const char *input, char *output) if (outputcnt) *output = 0; - pr_debug("[PROCESS_MACROS] OUTPUT len %d: \"%s\"\n", + pr_debug("[PROCESS_MACROS] OUTPUT len %zu: \"%s\"\n", strlen (output_start), output_start); } diff --git a/common/ubiformat.c b/common/ubiformat.c index 9fe1c7c501..0811525bd2 100644 --- a/common/ubiformat.c +++ b/common/ubiformat.c @@ -235,6 +235,9 @@ static int flash_image(struct ubiformat_args *args, struct mtd_info *mtd, int err, new_len; long long ec; + if (si->ec[eb] == EB_BAD) + continue; + if (!args->quiet && !args->verbose) { if (is_timeout(lastprint, 300 * MSECOND) || eb == eb_cnt - 1) { @@ -244,9 +247,6 @@ static int flash_image(struct ubiformat_args *args, struct mtd_info *mtd, } } - if (si->ec[eb] == EB_BAD) - continue; - if (args->verbose) { normsg_cont("eraseblock %d: erase", eb); } @@ -357,6 +357,9 @@ static int format(struct ubiformat_args *args, struct mtd_info *mtd, for (eb = start_eb; eb < eb_cnt; eb++) { long long ec; + if (si->ec[eb] == EB_BAD) + continue; + if (!args->quiet && !args->verbose) { if (is_timeout(lastprint, 300 * MSECOND) || eb == eb_cnt - 1) { @@ -366,9 +369,6 @@ static int format(struct ubiformat_args *args, struct mtd_info *mtd, } } - if (si->ec[eb] == EB_BAD) - continue; - if (args->override_ec) ec = args->ec; else if (si->ec[eb] <= EC_MAX) diff --git a/defaultenv/defaultenv-2-base/boot/bnet b/defaultenv/defaultenv-2-base/boot/bnet new file mode 100644 index 0000000000..e378acd1e6 --- /dev/null +++ b/defaultenv/defaultenv-2-base/boot/bnet @@ -0,0 +1,7 @@ +#!/bin/sh + +# script to boot barebox over tftp + +path="/mnt/tftp" + +global.bootm.image="${path}/${global.user}-barebox-${global.hostname}" diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 4acc4cfa1e..1fd890542e 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -177,7 +177,7 @@ int register_device(struct device_d *new_device) new_device->id = get_free_deviceid(new_device->name); } else { if (get_device_by_name_id(new_device->name, new_device->id)) { - eprintf("register_device: already registered %s\n", + pr_err("register_device: already registered %s\n", dev_name(new_device)); return -EINVAL; } diff --git a/drivers/clk/imx/clk-cpu.c b/drivers/clk/imx/clk-cpu.c index 5ac0ed1789..473500131e 100644 --- a/drivers/clk/imx/clk-cpu.c +++ b/drivers/clk/imx/clk-cpu.c @@ -111,8 +111,10 @@ struct clk *imx_clk_cpu(const char *name, const char *parent_name, cpu->clk.num_parents = 1; ret = clk_register(&cpu->clk); - if (ret) + if (ret) { free(cpu); + return NULL; + } return &cpu->clk; } diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index 3caf72503a..337a7a2e13 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -1,3 +1,5 @@ +menu "Clocksource" + config ARCH_HAS_IMX_GPT bool @@ -80,3 +82,10 @@ config CLOCKSOURCE_ARM_GLOBAL_TIMER config CLOCKSOURCE_IMX_GPT def_bool y depends on ARCH_HAS_IMX_GPT + +config CLOCKSOURCE_DW_APB_TIMER + bool "DW APB timer driver" + help + Enables the support for the dw_apb timer. + +endmenu diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index ce4d74137a..ab78f0700d 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile @@ -14,3 +14,4 @@ obj-$(CONFIG_CLOCKSOURCE_ATMEL_PIT) += timer-atmel-pit.o obj-$(CONFIG_CLOCKSOURCE_ARMV8_TIMER) += armv8-timer.o obj-$(CONFIG_CLOCKSOURCE_ARM_GLOBAL_TIMER) += arm_global_timer.o obj-$(CONFIG_CLOCKSOURCE_IMX_GPT) += timer-imx-gpt.o +obj-$(CONFIG_CLOCKSOURCE_DW_APB_TIMER) += dw_apb_timer.o diff --git a/drivers/clocksource/dw_apb_timer.c b/drivers/clocksource/dw_apb_timer.c new file mode 100644 index 0000000000..82ad6bccbc --- /dev/null +++ b/drivers/clocksource/dw_apb_timer.c @@ -0,0 +1,148 @@ +/* + * (C) Copyright 2009 Intel Corporation + * Author: Jacob Pan (jacob.jun.pan@intel.com) + * + * Shared with ARM platforms, Jamie Iles, Picochip 2011 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Support for the Synopsys DesignWare APB Timers. + * + * + * Taken from linux-4.9 kernel and adapted to barebox. + */ +#include <common.h> +#include <clock.h> +#include <init.h> + +#include <linux/clk.h> +#include <linux/err.h> + +#define APBT_MIN_PERIOD 4 +#define APBT_MIN_DELTA_USEC 200 + +#define APBTMR_N_LOAD_COUNT 0x00 +#define APBTMR_N_CURRENT_VALUE 0x04 +#define APBTMR_N_CONTROL 0x08 +#define APBTMR_N_EOI 0x0c +#define APBTMR_N_INT_STATUS 0x10 + +#define APBTMRS_INT_STATUS 0xa0 +#define APBTMRS_EOI 0xa4 +#define APBTMRS_RAW_INT_STATUS 0xa8 +#define APBTMRS_COMP_VERSION 0xac + +#define APBTMR_CONTROL_ENABLE (1 << 0) +/* 1: periodic, 0:free running. */ +#define APBTMR_CONTROL_MODE_PERIODIC (1 << 1) +#define APBTMR_CONTROL_INT (1 << 2) + +#define APBTMRS_REG_SIZE 0x14 + +struct dw_apb_timer { + void __iomem *base; + unsigned long freq; + int irq; +}; + +static struct dw_apb_timer timer; + +static inline u32 apbt_readl(struct dw_apb_timer *timer, unsigned long offs) +{ + return readl(timer->base + offs); +} + +static inline void apbt_writel(struct dw_apb_timer *timer, u32 val, + unsigned long offs) +{ + writel(val, timer->base + offs); +} + +/** + * dw_apb_clocksource_start() - start the clocksource counting. + * + * @clksrc: The clocksource to start. + * + * This is used to start the clocksource before registration and can be used + * to enable calibration of timers. + */ +static int dw_apb_clocksource_start(struct clocksource *clksrc) +{ + /* + * start count down from 0xffff_ffff. this is done by toggling the + * enable bit then load initial load count to ~0. + */ + uint32_t ctrl = apbt_readl(&timer, APBTMR_N_CONTROL); + + ctrl &= ~APBTMR_CONTROL_ENABLE; + apbt_writel(&timer, ctrl, APBTMR_N_CONTROL); + apbt_writel(&timer, ~0, APBTMR_N_LOAD_COUNT); + + /* enable, mask interrupt */ + ctrl &= ~APBTMR_CONTROL_MODE_PERIODIC; + ctrl |= (APBTMR_CONTROL_ENABLE | APBTMR_CONTROL_INT); + apbt_writel(&timer, ctrl, APBTMR_N_CONTROL); + + return 0; +} + +static uint64_t dw_apb_clocksource_read(void) +{ + return (uint64_t) ~apbt_readl(&timer, APBTMR_N_CURRENT_VALUE); +} + +static struct clocksource dw_apb_clksrc = { + .init = dw_apb_clocksource_start, + .read = dw_apb_clocksource_read, + .mask = CLOCKSOURCE_MASK(32), + .shift = 0, +}; + +static int dw_apb_timer_probe(struct device_d *dev) +{ + struct device_node *np = dev->device_node; + struct resource *iores; + struct clk *clk; + uint32_t clk_freq; + + /* use only one timer */ + if (timer.base) + return -EBUSY; + + iores = dev_request_mem_resource(dev, 0); + if (IS_ERR(iores)) { + dev_err(dev, "could not get memory region\n"); + return PTR_ERR(iores); + } + + timer.base = IOMEM(iores->start); + + /* Get clock frequency */ + clk = of_clk_get(np, 0); + if (IS_ERR(clk)) { + pr_err("Failed to get CPU clock: %ld\n", PTR_ERR(clk)); + return PTR_ERR(clk); + } + + clk_freq = clk_get_rate(clk); + clk_put(clk); + + dw_apb_clksrc.mult = clocksource_hz2mult(clk_freq, dw_apb_clksrc.shift); + + return init_clock(&dw_apb_clksrc); +} + +static struct of_device_id dw_apb_timer_dt_ids[] = { + { .compatible = "snps,dw-apb-timer", }, + { } +}; + +static struct driver_d dw_apb_timer_driver = { + .name = "dw-apb-timer", + .probe = dw_apb_timer_probe, + .of_compatible = DRV_OF_COMPAT(dw_apb_timer_dt_ids), +}; + +device_platform_driver(dw_apb_timer_driver); diff --git a/drivers/mfd/da9063.c b/drivers/mfd/da9063.c index b6114a614b..a7fff2c5bf 100644 --- a/drivers/mfd/da9063.c +++ b/drivers/mfd/da9063.c @@ -201,7 +201,7 @@ static int da9062_device_init(struct da9063 *priv) priv->client1 = i2c_new_dummy(priv->client->adapter, priv->client->addr + 1); - if (!priv) { + if (!priv->client1) { dev_warn(priv->dev, "failed to create bank 1 device\n"); /* TODO: return -EINVAL; i2c api does not return more * details */ diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c index 797cdc2ba6..4c1725d096 100644 --- a/drivers/mtd/nand/atmel_nand.c +++ b/drivers/mtd/nand/atmel_nand.c @@ -788,7 +788,6 @@ static int pmecc_build_galois_table(unsigned int mm, int16_t *index_of, case 3: case 4: case 6: - case 15: p[1] = 1; break; case 5: diff --git a/drivers/net/e1000/eeprom.c b/drivers/net/e1000/eeprom.c index 180b32ede8..ce74a8b200 100644 --- a/drivers/net/e1000/eeprom.c +++ b/drivers/net/e1000/eeprom.c @@ -883,7 +883,7 @@ static int e1000_flash_mode_erase_chunk(struct e1000_hw *hw, loff_t offset, ret = e1000_poll_reg(hw, E1000_FLSWCTL, E1000_FLSWCTL_DONE | E1000_FLSWCTL_FLBUSY, E1000_FLSWCTL_DONE, - 10 * SECOND); + 40 * SECOND); if (ret < 0) { dev_err(hw->dev, "Timeout waiting for FLSWCTL.DONE to be set (erase)\n"); diff --git a/drivers/net/e1000/main.c b/drivers/net/e1000/main.c index bb6ab4eb03..caa7274a8d 100644 --- a/drivers/net/e1000/main.c +++ b/drivers/net/e1000/main.c @@ -1130,7 +1130,7 @@ static int32_t e1000_set_d3_lplu_state_off(struct e1000_hw *hw) { uint32_t phy_ctrl = 0; int32_t ret_val; - uint16_t phy_data; + uint16_t phy_data = 0; DEBUGFUNC(); /* During driver activity LPLU should not be used or it will attain link diff --git a/drivers/of/partition.c b/drivers/of/partition.c index aa6e601b7f..2848b9636d 100644 --- a/drivers/of/partition.c +++ b/drivers/of/partition.c @@ -186,11 +186,11 @@ static int of_partition_fixup(struct device_node *root, void *ctx) return ret; } - of_property_write_u32(partnode, "#size-cells", n_cells); + ret = of_property_write_u32(partnode, "#size-cells", n_cells); if (ret) return ret; - of_property_write_u32(partnode, "#address-cells", n_cells); + ret = of_property_write_u32(partnode, "#address-cells", n_cells); if (ret) return ret; diff --git a/drivers/pinctrl/pinctrl-tegra30.c b/drivers/pinctrl/pinctrl-tegra30.c index d9b49c57d9..ffb04eebbf 100644 --- a/drivers/pinctrl/pinctrl-tegra30.c +++ b/drivers/pinctrl/pinctrl-tegra30.c @@ -658,8 +658,8 @@ static int pinctrl_tegra30_set_drvstate(struct pinctrl_tegra30 *ctrl, break; } } - /* if no matching drivegroup is found */ - if (i == ctrl->drvdata->num_drvgrps) + + if (!group) return 0; regaddr = ctrl->regs.ctrl + (group->reg >> 2); diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index bb597305e5..f1feee4689 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c @@ -348,10 +348,10 @@ static int ds1307_probe(struct device_d *dev) ds1307->regs[1] &= ~DS1341_BIT_ECLK; /* - * Let's set additionale RTC bits to + * Let's set additional RTC bits to * facilitate maximum power saving. */ - ds1307->regs[0] |= DS1341_BIT_DOSF; + ds1307->regs[1] |= DS1341_BIT_DOSF; ds1307->regs[0] &= ~DS1341_BIT_EGFIL; i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index 729f752128..243656d443 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c @@ -288,8 +288,7 @@ static int at91_ep_enable(struct usb_ep *_ep, u16 maxpacket; u32 tmp; - if (!_ep || !ep - || !desc || ep->desc + if (!desc || ep->desc || _ep->name == ep0name || desc->bDescriptorType != USB_DT_ENDPOINT || (maxpacket = le16_to_cpu(desc->wMaxPacketSize)) == 0 diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c index feaa856451..c8f55ac32c 100644 --- a/drivers/usb/musb/musb_gadget_ep0.c +++ b/drivers/usb/musb/musb_gadget_ep0.c @@ -110,6 +110,11 @@ static int service_tx_status_request( break; } + if (epnum >= MUSB_C_NUM_EPS) { + handled = -EINVAL; + break; + } + is_in = epnum & USB_DIR_IN; if (is_in) { epnum &= 0x0f; @@ -119,7 +124,7 @@ static int service_tx_status_request( } regs = musb->endpoints[epnum].regs; - if (epnum >= MUSB_C_NUM_EPS || !ep->desc) { + if (!ep->desc) { handled = -EINVAL; break; } diff --git a/drivers/video/ssd1307fb.c b/drivers/video/ssd1307fb.c index d68f0c5056..70077e43a8 100644 --- a/drivers/video/ssd1307fb.c +++ b/drivers/video/ssd1307fb.c @@ -548,8 +548,10 @@ static int ssd1307fb_probe(struct device_d *dev) /* clear display */ array = ssd1307fb_alloc_array(par->width * par->height / 8, SSD1307FB_DATA); - if (!array) - return -ENOMEM; + if (!array) { + ret = -ENOMEM; + goto panel_init_error; + } for (i = 0; i < (par->height / 8); i++) { for (j = 0; j < par->width; j++) { @@ -569,6 +571,7 @@ static int ssd1307fb_probe(struct device_d *dev) panel_init_error: reset_oled_error: + free(vmem); fb_alloc_error: regulator_disable(par->vbat); free(info); @@ -1526,7 +1526,7 @@ static struct dentry *__lookup_hash(const struct qstr *name, { struct dentry *dentry; struct dentry *old; - struct inode *dir = base->d_inode; + struct inode *dir; if (!base) return ERR_PTR(-ENOENT); @@ -1539,6 +1539,7 @@ static struct dentry *__lookup_hash(const struct qstr *name, if (unlikely(!dentry)) return ERR_PTR(-ENOMEM); + dir = base->d_inode; old = dir->i_op->lookup(dir, dentry, flags); if (IS_ERR(old)) { dput(dentry); @@ -2527,8 +2528,6 @@ EXPORT_SYMBOL(opendir); int closedir(DIR *dir) { - int ret; - if (!dir) { errno = EBADF; return -EBADF; @@ -2536,7 +2535,7 @@ int closedir(DIR *dir) release_dir(dir); - return ret; + return 0; } EXPORT_SYMBOL(closedir); diff --git a/include/common.h b/include/common.h index f52c7e430c..11d26cb3db 100644 --- a/include/common.h +++ b/include/common.h @@ -112,16 +112,6 @@ void shutdown_barebox(void); #define PAGE_ALIGN(s) ALIGN(s, PAGE_SIZE) #define PAGE_ALIGN_DOWN(x) ALIGN_DOWN(x, PAGE_SIZE) -int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size, int swab); - -#define DUMP_PREFIX_OFFSET 0 -static inline void print_hex_dump(const char *level, const char *prefix_str, - int prefix_type, int rowsize, int groupsize, - const void *buf, size_t len, bool ascii) -{ - memory_display(buf, 0, len, 4, 0); -} - int mem_parse_options(int argc, char *argv[], char *optstr, int *mode, char **sourcefile, char **destfile, int *swab); #define RW_BUF_SIZE (unsigned)4096 diff --git a/include/printk.h b/include/printk.h index 4384fb85ea..aaad07552e 100644 --- a/include/printk.h +++ b/include/printk.h @@ -91,7 +91,7 @@ static inline int pr_print(int level, const char *format, ...) #define pr_debug(fmt, arg...) __pr_printk(7, pr_fmt(fmt), ##arg) #define debug(fmt, arg...) __pr_printk(7, pr_fmt(fmt), ##arg) #define pr_vdebug(fmt, arg...) __pr_printk(8, pr_fmt(fmt), ##arg) -#define pr_cont(fmt, arg...) __pr_printk(0, fmt, ##arg) +#define pr_cont(fmt, arg...) __pr_printk(-1, fmt, ##arg) #define printk_once(fmt, ...) \ ({ \ @@ -103,6 +103,25 @@ static inline int pr_print(int level, const char *format, ...) } \ }) +int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size, + int swab); +int __pr_memory_display(int level, const void *addr, loff_t offs, unsigned nbytes, + int size, int swab, const char *format, ...); + +#define pr_memory_display(level, addr, offs, nbytes, size, swab) \ + ({ \ + (level) <= LOGLEVEL ? __pr_memory_display((level), (addr), \ + (offs), (nbytes), (size), (swab), pr_fmt("")) : 0; \ + }) + +#define DUMP_PREFIX_OFFSET 0 +static inline void print_hex_dump(const char *level, const char *prefix_str, + int prefix_type, int rowsize, int groupsize, + const void *buf, size_t len, bool ascii) +{ + memory_display(buf, 0, len, 4, 0); +} + struct log_entry { struct list_head list; char *msg; diff --git a/lib/bootstrap/disk.c b/lib/bootstrap/disk.c index a55d5d77f4..fd016166e6 100644 --- a/lib/bootstrap/disk.c +++ b/lib/bootstrap/disk.c @@ -18,7 +18,7 @@ void* bootstrap_read_disk(const char *dev, const char *fstype) { int ret; void *buf; - int len; + size_t len; const char *path = "/"; ret = mount(dev, fstype, path, NULL); diff --git a/lib/getopt.c b/lib/getopt.c index 847830c22b..55852ba133 100644 --- a/lib/getopt.c +++ b/lib/getopt.c @@ -13,6 +13,7 @@ * GNU General Public License for more details. * */ +#define pr_fmt(fmt) "getopt: " fmt #include <common.h> #include <module.h> diff --git a/lib/gui/lodepng.c b/lib/gui/lodepng.c index ba21cd235f..fa8980883b 100644 --- a/lib/gui/lodepng.c +++ b/lib/gui/lodepng.c @@ -1168,13 +1168,7 @@ static unsigned inflateHuffmanBlock(ucvector* out, const unsigned char* in, size code_d = huffmanDecodeSymbol(in, bp, &tree_d, inbitlength); if(code_d > 29) { - if(code_ll == (unsigned)(-1)) /*huffmanDecodeSymbol returns (unsigned)(-1) in case of error*/ - { - /*return error code 10 or 11 depending on the situation that happened in huffmanDecodeSymbol - (10=no endcode, 11=wrong jump outside of tree)*/ - error = (*bp) > inlength * 8 ? 10 : 11; - } - else error = 18; /*error: invalid distance code (30-31 are never used)*/ + error = 18; /*error: invalid distance code (30-31 are never used)*/ break; } distance = DISTANCEBASE[code_d]; diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 9a6f6e2298..4e17347a84 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1,16 +1,18 @@ #!/usr/bin/perl -w +# SPDX-License-Identifier: GPL-2.0 +# # (c) 2001, Dave Jones. (the file handling bit) # (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit) # (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite) # (c) 2008-2010 Andy Whitcroft <apw@canonical.com> -# Licensed under the terms of the GNU GPL License version 2 +# (c) 2010-2018 Joe Perches <joe@perches.com> use strict; my $P = $0; $P =~ s@.*/@@g; -my $V = '0.31'; +my $V = '0.32'; use Getopt::Long qw(:config no_auto_abbrev); @@ -26,9 +28,13 @@ my $check = 0; my $summary = 1; my $mailback = 0; my $summary_file = 0; +my $show_types = 0; my $root; my %debug; +my %ignore_type = (); +my @ignore = (); my $help = 0; +my $configuration_file = ".checkpatch.conf"; sub help { my ($exitcode) = @_; @@ -46,6 +52,8 @@ Options: --terse one line per report -f, --file treat FILE as regular source file --subjective, --strict enable more subjective tests + --ignore TYPE(,TYPE2...) ignore various comma separated message types + --show-types show the message "types" in the output --root=PATH PATH to the kernel tree root --no-summary suppress the per-file summary --mailback only produce a report in case of warnings/errors @@ -63,6 +71,32 @@ EOM exit($exitcode); } +my $conf = which_conf($configuration_file); +if (-f $conf) { + my @conf_args; + open(my $conffile, '<', "$conf") + or warn "$P: Can't find a readable $configuration_file file $!\n"; + + while (<$conffile>) { + my $line = $_; + + $line =~ s/\s*\n?$//g; + $line =~ s/^\s*//g; + $line =~ s/\s+/ /g; + + next if ($line =~ m/^\s*#/); + next if ($line =~ m/^\s*$/); + + my @words = split(" ", $line); + foreach my $word (@words) { + last if ($word =~ m/^#/); + push (@conf_args, $word); + } + } + close($conffile); + unshift(@ARGV, @conf_args) if @conf_args; +} + GetOptions( 'q|quiet+' => \$quiet, 'tree!' => \$tree, @@ -73,6 +107,8 @@ GetOptions( 'f|file!' => \$file, 'subjective!' => \$check, 'strict!' => \$check, + 'ignore=s' => \@ignore, + 'show-types!' => \$show_types, 'root=s' => \$root, 'summary!' => \$summary, 'mailback!' => \$mailback, @@ -93,6 +129,19 @@ if ($#ARGV < 0) { exit(1); } +@ignore = split(/,/, join(',',@ignore)); +foreach my $word (@ignore) { + $word =~ s/\s*\n?$//g; + $word =~ s/^\s*//g; + $word =~ s/\s+/ /g; + $word =~ tr/[a-z]/[A-Z]/; + + next if ($word =~ m/^\s*#/); + next if ($word =~ m/^\s*$/); + + $ignore_type{$word}++; +} + my $dbg_values = 0; my $dbg_possible = 0; my $dbg_type = 0; @@ -341,6 +390,18 @@ sub top_of_kernel_tree { return 1; } +sub which_conf { + my ($conf) = @_; + + foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) { + if (-e "$path/$conf") { + return "$path/$conf"; + } + } + + return ""; +} + sub expand_tabs { my ($str) = @_; @@ -1086,12 +1147,21 @@ sub possible { my $prefix = ''; +sub show_type { + return !defined $ignore_type{$_[0]}; +} + sub report { - if (defined $tst_only && $_[0] !~ /\Q$tst_only\E/) { + if (!show_type($_[1]) || + (defined $tst_only && $_[2] !~ /\Q$tst_only\E/)) { return 0; } - my $line = $prefix . $_[0]; - + my $line; + if ($show_types) { + $line = "$prefix$_[0]:$_[1]: $_[2]\n"; + } else { + $line = "$prefix$_[0]: $_[2]\n"; + } $line = (split('\n', $line))[0] . "\n" if ($terse); push(our @report, $line); @@ -1101,20 +1171,21 @@ sub report { sub report_dump { our @report; } + sub ERROR { - if (report("ERROR: $_[0]\n")) { + if (report("ERROR", $_[0], $_[1])) { our $clean = 0; our $cnt_error++; } } sub WARN { - if (report("WARNING: $_[0]\n")) { + if (report("WARNING", $_[0], $_[1])) { our $clean = 0; our $cnt_warn++; } } sub CHK { - if ($check && report("CHECK: $_[0]\n")) { + if ($check && report("CHECK", $_[0], $_[1])) { our $clean = 0; our $cnt_chk++; } @@ -1143,7 +1214,8 @@ sub check_absolute_file { ##print "prefix<$prefix>\n"; if ($prefix ne ".../") { - WARN("use relative pathname instead of absolute in changelog text\n" . $herecurr); + WARN("USE_RELATIVE_PATH", + "use relative pathname instead of absolute in changelog text\n" . $herecurr); } } @@ -1340,11 +1412,13 @@ sub process { $p1_prefix = $1; if (!$file && $tree && $p1_prefix ne '' && -e "$root/$p1_prefix") { - WARN("patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n"); + WARN("PATCH_PREFIX", + "patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n"); } if ($realfile =~ m@^include/asm/@) { - ERROR("do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n"); + ERROR("MODIFIED_INCLUDE_ASM", + "do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n"); } next; } @@ -1361,7 +1435,8 @@ sub process { if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) { my $permhere = $here . "FILE: $realfile\n"; if ($realfile =~ /(Makefile|Kconfig|\.c|\.h|\.S|\.tmpl)$/) { - ERROR("do not set execute permissions for source files\n" . $permhere); + ERROR("EXECUTE_PERMISSIONS", + "do not set execute permissions for source files\n" . $permhere); } } @@ -1370,18 +1445,21 @@ sub process { # This is a signoff, if ugly, so do not double report. $signoff++; if (!($line =~ /^\s*Signed-off-by:/)) { - WARN("Signed-off-by: is the preferred form\n" . + WARN("BAD_SIGN_OFF", + "Signed-off-by: is the preferred form\n" . $herecurr); } if ($line =~ /^\s*signed-off-by:\S/i) { - WARN("space required after Signed-off-by:\n" . + WARN("BAD_SIGN_OFF", + "space required after Signed-off-by:\n" . $herecurr); } } # Check for wrappage within a valid hunk of the file if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) { - ERROR("patch seems to be corrupt (line wrapped?)\n" . + ERROR("CORRUPTED_PATCH", + "patch seems to be corrupt (line wrapped?)\n" . $herecurr) if (!$emitted_corrupt++); } @@ -1408,7 +1486,8 @@ sub process { my $ptr = substr($blank, 0, length($utf8_prefix)) . "^"; my $hereptr = "$hereline$ptr\n"; - ERROR("Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr); + ERROR("INVALID_UTF8", + "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr); } # ignore non-hunk lines and lines being removed @@ -1417,11 +1496,13 @@ sub process { #trailing whitespace if ($line =~ /^\+.*\015/) { my $herevet = "$here\n" . cat_vet($rawline) . "\n"; - ERROR("DOS line endings\n" . $herevet); + ERROR("DOS_LINE_ENDINGS", + "DOS line endings\n" . $herevet); } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) { my $herevet = "$here\n" . cat_vet($rawline) . "\n"; - ERROR("trailing whitespace\n" . $herevet); + ERROR("TRAILING_WHITESPACE", + "trailing whitespace\n" . $herevet); $rpt_cleaners = 1; } @@ -1462,7 +1543,8 @@ sub process { } $length++; } - WARN("please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($is_end && $length < 4); + WARN("CONFIG_DESCRIPTION", + "please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($is_end && $length < 4); #print "is_end<$is_end> length<$length>\n"; } @@ -1487,7 +1569,7 @@ sub process { $compat3 =~ s/\,([a-z]*)[0-9]*\-/\,$1<\.\*>\-/; `grep -Erq "$compat|$compat2|$compat3" $dt_path`; if ( $? >> 8 ) { - WARN( + WARN("UNDOCUMENTED_DT_STRING", "DT compatible string \"$compat\" appears un-documented -- check $dt_path\n" . $herecurr); } @@ -1495,7 +1577,7 @@ sub process { my $vendor = $1; `grep -Eq "^$vendor\\b" $vp_file`; if ( $? >> 8 ) { - WARN( + WARN("UNDOCUMENTED_DT_STRING", "DT compatible string vendor \"$vendor\" appears un-documented -- check $vp_file\n" . $herecurr); } } @@ -1511,28 +1593,33 @@ sub process { $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) && $length > 80) { - WARN("line over 80 characters\n" . $herecurr); + WARN("LONG_LINE", + "line over 80 characters\n" . $herecurr); } # check for spaces before a quoted newline if ($rawline =~ /^.*\".*\s\\n/) { - WARN("unnecessary whitespace before a quoted newline\n" . $herecurr); + WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE", + "unnecessary whitespace before a quoted newline\n" . $herecurr); } # check for adding lines without a newline. if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) { - WARN("adding a line without newline at end of file\n" . $herecurr); + WARN("MISSING_EOF_NEWLINE", + "adding a line without newline at end of file\n" . $herecurr); } # Blackfin: use hi/lo macros if ($realfile =~ m@arch/blackfin/.*\.S$@) { if ($line =~ /\.[lL][[:space:]]*=.*&[[:space:]]*0x[fF][fF][fF][fF]/) { my $herevet = "$here\n" . cat_vet($line) . "\n"; - ERROR("use the LO() macro, not (... & 0xFFFF)\n" . $herevet); + ERROR("LO_MACRO", + "use the LO() macro, not (... & 0xFFFF)\n" . $herevet); } if ($line =~ /\.[hH][[:space:]]*=.*>>[[:space:]]*16/) { my $herevet = "$here\n" . cat_vet($line) . "\n"; - ERROR("use the HI() macro, not (... >> 16)\n" . $herevet); + ERROR("HI_MACRO", + "use the HI() macro, not (... >> 16)\n" . $herevet); } } @@ -1544,14 +1631,16 @@ sub process { if ($rawline =~ /^\+\s* \t\s*\S/ || $rawline =~ /^\+\s* \s*/) { my $herevet = "$here\n" . cat_vet($rawline) . "\n"; - ERROR("code indent should use tabs where possible\n" . $herevet); + ERROR("CODE_INDENT", + "code indent should use tabs where possible\n" . $herevet); $rpt_cleaners = 1; } # check for space before tabs. if ($rawline =~ /^\+/ && $rawline =~ / \t/) { my $herevet = "$here\n" . cat_vet($rawline) . "\n"; - WARN("please, no space before tabs\n" . $herevet); + WARN("SPACE_BEFORE_TAB", + "please, no space before tabs\n" . $herevet); } # check for spaces at the beginning of a line. @@ -1561,7 +1650,8 @@ sub process { # 3) hanging labels if ($rawline =~ /^\+ / && $line !~ /\+ *(?:$;|#|$Ident:)/) { my $herevet = "$here\n" . cat_vet($rawline) . "\n"; - WARN("please, no spaces at the start of a line\n" . $herevet); + WARN("LEADING_SPACE", + "please, no spaces at the start of a line\n" . $herevet); } # check we are in a valid C source file if not then ignore this hunk @@ -1569,17 +1659,20 @@ sub process { # check for RCS/CVS revision markers if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) { - WARN("CVS style keyword markers, these will _not_ be updated\n". $herecurr); + WARN("CVS_KEYWORD", + "CVS style keyword markers, these will _not_ be updated\n". $herecurr); } # Blackfin: don't use __builtin_bfin_[cs]sync if ($line =~ /__builtin_bfin_csync/) { my $herevet = "$here\n" . cat_vet($line) . "\n"; - ERROR("use the CSYNC() macro in asm/blackfin.h\n" . $herevet); + ERROR("CSYNC", + "use the CSYNC() macro in asm/blackfin.h\n" . $herevet); } if ($line =~ /__builtin_bfin_ssync/) { my $herevet = "$here\n" . cat_vet($line) . "\n"; - ERROR("use the SSYNC() macro in asm/blackfin.h\n" . $herevet); + ERROR("SSYNC", + "use the SSYNC() macro in asm/blackfin.h\n" . $herevet); } # Check for potential 'bare' types @@ -1668,7 +1761,8 @@ sub process { } } if ($err ne '') { - ERROR("switch and case should be at the same indent\n$hereline$err"); + ERROR("SWITCH_CASE_INDENT_LEVEL", + "switch and case should be at the same indent\n$hereline$err"); } } @@ -1696,7 +1790,8 @@ sub process { #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n"; if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) { - ERROR("that open brace { should be on the previous line\n" . + ERROR("OPEN_BRACE", + "that open brace { should be on the previous line\n" . "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n"); } if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ && @@ -1705,7 +1800,8 @@ sub process { { my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]); if ($nindent > $indent) { - WARN("trailing semicolon indicates no statements, indent implies otherwise\n" . + WARN("TRAILING_SEMICOLON", + "trailing semicolon indicates no statements, indent implies otherwise\n" . "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n"); } } @@ -1793,7 +1889,8 @@ sub process { if ($check && (($sindent % 8) != 0 || ($sindent <= $indent && $s ne ''))) { - WARN("suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n"); + WARN("SUSPECT_CODE_INDENT", + "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n"); } } @@ -1816,18 +1913,22 @@ sub process { # TEST: allow direct testing of the type matcher. if ($dbg_type) { if ($line =~ /^.\s*$Declare\s*$/) { - ERROR("TEST: is type\n" . $herecurr); + ERROR("TEST_TYPE", + "TEST: is type\n" . $herecurr); } elsif ($dbg_type > 1 && $line =~ /^.+($Declare)/) { - ERROR("TEST: is not type ($1 is)\n". $herecurr); + ERROR("TEST_NOT_TYPE", + "TEST: is not type ($1 is)\n". $herecurr); } next; } # TEST: allow direct testing of the attribute matcher. if ($dbg_attr) { if ($line =~ /^.\s*$Modifier\s*$/) { - ERROR("TEST: is attr\n" . $herecurr); + ERROR("TEST_ATTR", + "TEST: is attr\n" . $herecurr); } elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) { - ERROR("TEST: is not attr ($1 is)\n". $herecurr); + ERROR("TEST_NOT_ATTR", + "TEST: is not attr ($1 is)\n". $herecurr); } next; } @@ -1835,7 +1936,8 @@ sub process { # check for initialisation to aggregates open brace on the next line if ($line =~ /^.\s*{/ && $prevline =~ /(?:^|[^=])=\s*$/) { - ERROR("that open brace { should be on the previous line\n" . $hereprev); + ERROR("OPEN_BRACE", + "that open brace { should be on the previous line\n" . $hereprev); } # @@ -1846,14 +1948,16 @@ sub process { if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) { my $path = $1; if ($path =~ m{//}) { - ERROR("malformed #include filename\n" . + ERROR("MALFORMED_INCLUDE", + "malformed #include filename\n" . $herecurr); } } # no C99 // comments if ($line =~ m{//}) { - ERROR("do not use C99 // comments\n" . $herecurr); + ERROR("C99_COMMENTS", + "do not use C99 // comments\n" . $herecurr); } # Remove C99 comments. $line =~ s@//.*@@; @@ -1900,35 +2004,41 @@ sub process { } if (defined $suppress_export{$linenr} && $suppress_export{$linenr} == 2) { - WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); + WARN("EXPORT_SYMBOL", + "EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); } # check for global initialisers. if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) { - ERROR("do not initialise globals to 0 or NULL\n" . + ERROR("GLOBAL_INITIALISERS", + "do not initialise globals to 0 or NULL\n" . $herecurr); } # check for static initialisers. if ($line =~ /\bstatic\s.*=\s*(0|NULL|false)\s*;/) { - ERROR("do not initialise statics to 0 or NULL\n" . + ERROR("INITIALISED_STATIC", + "do not initialise statics to 0 or NULL\n" . $herecurr); } # check for static const char * arrays. if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) { - WARN("static const char * array should probably be static const char * const\n" . + WARN("STATIC_CONST_CHAR_ARRAY", + "static const char * array should probably be static const char * const\n" . $herecurr); } # check for static char foo[] = "bar" declarations. if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) { - WARN("static char array declaration should probably be static const char\n" . + WARN("STATIC_CONST_CHAR_ARRAY", + "static char array declaration should probably be static const char\n" . $herecurr); } # check for declarations of struct pci_device_id if ($line =~ /\bstruct\s+pci_device_id\s+\w+\s*\[\s*\]\s*\=\s*\{/) { - WARN("Use DEFINE_PCI_DEVICE_TABLE for struct pci_device_id\n" . $herecurr); + WARN("DEFINE_PCI_DEVICE_TABLE", + "Use DEFINE_PCI_DEVICE_TABLE for struct pci_device_id\n" . $herecurr); } # check for new typedefs, only function parameters and sparse annotations @@ -1938,7 +2048,8 @@ sub process { $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ && $line !~ /\b$typeTypedefs\b/ && $line !~ /\b__bitwise(?:__|)\b/) { - WARN("do not add new typedefs\n" . $herecurr); + WARN("NEW_TYPEDEFS", + "do not add new typedefs\n" . $herecurr); } # * goes on variable not on type @@ -1956,7 +2067,8 @@ sub process { #print "from<$from> to<$to>\n"; if ($from ne $to) { - ERROR("\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr); + ERROR("POINTER_LOCATION", + "\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr); } } elsif ($line =~ m{\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident)}) { my ($from, $to, $ident) = ($1, $1, $2); @@ -1973,7 +2085,8 @@ sub process { #print "from<$from> to<$to> ident<$ident>\n"; if ($from ne $to && $ident !~ /^$Modifier$/) { - ERROR("\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr); + ERROR("POINTER_LOCATION", + "\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr); } } @@ -1985,7 +2098,8 @@ sub process { # } if ($line =~ /\bLINUX_VERSION_CODE\b/) { - WARN("LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr); + WARN("LINUX_VERSION_CODE", + "LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr); } # printk should use KERN_* levels. Note that follow on printk's on the @@ -2007,7 +2121,8 @@ sub process { } } if ($ok == 0) { - WARN("printk() should include KERN_ facility level\n" . $herecurr); + WARN("PRINTK_WITHOUT_KERN_LEVEL", + "printk() should include KERN_ facility level\n" . $herecurr); } } @@ -2015,18 +2130,21 @@ sub process { # or if closed on same line if (($line=~/$Type\s*$Ident\(.*\).*\s\{/) and !($line=~/\#\s*define.*do\s\{/) and !($line=~/}/)) { - ERROR("open brace '{' following function declarations go on the next line\n" . $herecurr); + ERROR("OPEN_BRACE", + "open brace '{' following function declarations go on the next line\n" . $herecurr); } # open braces for enum, union and struct go on the same line. if ($line =~ /^.\s*{/ && $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) { - ERROR("open brace '{' following $1 go on the same line\n" . $hereprev); + ERROR("OPEN_BRACE", + "open brace '{' following $1 go on the same line\n" . $hereprev); } # missing space after union, struct or enum definition if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?(?:\s+$Ident)?[=\{]/) { - WARN("missing space after $1 definition\n" . $herecurr); + WARN("SPACING", + "missing space after $1 definition\n" . $herecurr); } # check for spacing round square brackets; allowed: @@ -2038,7 +2156,8 @@ sub process { if ($prefix !~ /$Type\s+$/ && ($where != 0 || $prefix !~ /^.\s+$/) && $prefix !~ /{\s+$/) { - ERROR("space prohibited before open square bracket '['\n" . $herecurr); + ERROR("BRACKET_SPACE", + "space prohibited before open square bracket '['\n" . $herecurr); } } @@ -2069,7 +2188,8 @@ sub process { } elsif ($ctx =~ /$Type$/) { } else { - WARN("space prohibited between function name and open parenthesis '('\n" . $herecurr); + WARN("SPACING", + "space prohibited between function name and open parenthesis '('\n" . $herecurr); } } # Check operator spacing. @@ -2143,7 +2263,8 @@ sub process { } elsif ($op eq ';') { if ($ctx !~ /.x[WEBC]/ && $cc !~ /^\\/ && $cc !~ /^;/) { - ERROR("space required after that '$op' $at\n" . $hereptr); + ERROR("SPACING", + "space required after that '$op' $at\n" . $hereptr); } # // is a comment @@ -2154,13 +2275,15 @@ sub process { # : when part of a bitfield } elsif ($op eq '->' || $opv eq ':B') { if ($ctx =~ /Wx.|.xW/) { - ERROR("spaces prohibited around that '$op' $at\n" . $hereptr); + ERROR("SPACING", + "spaces prohibited around that '$op' $at\n" . $hereptr); } # , must have a space on the right. } elsif ($op eq ',') { if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) { - ERROR("space required after that '$op' $at\n" . $hereptr); + ERROR("SPACING", + "space required after that '$op' $at\n" . $hereptr); } # '*' as part of a type definition -- reported already. @@ -2174,26 +2297,31 @@ sub process { $opv eq '*U' || $opv eq '-U' || $opv eq '&U' || $opv eq '&&U') { if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { - ERROR("space required before that '$op' $at\n" . $hereptr); + ERROR("SPACING", + "space required before that '$op' $at\n" . $hereptr); } if ($op eq '*' && $cc =~/\s*$Modifier\b/) { # A unary '*' may be const } elsif ($ctx =~ /.xW/) { - ERROR("space prohibited after that '$op' $at\n" . $hereptr); + ERROR("SPACING", + "space prohibited after that '$op' $at\n" . $hereptr); } # unary ++ and unary -- are allowed no space on one side. } elsif ($op eq '++' or $op eq '--') { if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) { - ERROR("space required one side of that '$op' $at\n" . $hereptr); + ERROR("SPACING", + "space required one side of that '$op' $at\n" . $hereptr); } if ($ctx =~ /Wx[BE]/ || ($ctx =~ /Wx./ && $cc =~ /^;/)) { - ERROR("space prohibited before that '$op' $at\n" . $hereptr); + ERROR("SPACING", + "space prohibited before that '$op' $at\n" . $hereptr); } if ($ctx =~ /ExW/) { - ERROR("space prohibited after that '$op' $at\n" . $hereptr); + ERROR("SPACING", + "space prohibited after that '$op' $at\n" . $hereptr); } @@ -2205,7 +2333,8 @@ sub process { $op eq '%') { if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) { - ERROR("need consistent spacing around '$op' $at\n" . + ERROR("SPACING", + "need consistent spacing around '$op' $at\n" . $hereptr); } @@ -2213,7 +2342,8 @@ sub process { # terminating a case value or a label. } elsif ($opv eq ':C' || $opv eq ':L') { if ($ctx =~ /Wx./) { - ERROR("space prohibited before that '$op' $at\n" . $hereptr); + ERROR("SPACING", + "space prohibited before that '$op' $at\n" . $hereptr); } # All the others need spaces both sides. @@ -2236,7 +2366,8 @@ sub process { } if ($ok == 0) { - ERROR("spaces required around that '$op' $at\n" . $hereptr); + ERROR("SPACING", + "spaces required around that '$op' $at\n" . $hereptr); } } $off += length($elements[$n + 1]); @@ -2245,7 +2376,8 @@ sub process { # check for multiple assignments if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) { - CHK("multiple assignments should be avoided\n" . $herecurr); + CHK("MULTIPLE_ASSIGNMENTS", + "multiple assignments should be avoided\n" . $herecurr); } ## # check for multiple declarations, allowing for a function declaration @@ -2259,45 +2391,53 @@ sub process { ## while ($ln =~ s/\([^\(\)]*\)//g) { ## } ## if ($ln =~ /,/) { -## WARN("declaring multiple variables together should be avoided\n" . $herecurr); +## WARN("MULTIPLE_DECLARATION", +## "declaring multiple variables together should be avoided\n" . $herecurr); ## } ## } #need space before brace following if, while, etc if (($line =~ /\(.*\)\{/ && $line !~ /\($Type\)\{/) || $line =~ /do\{/) { - ERROR("space required before the open brace '{'\n" . $herecurr); + ERROR("SPACING", + "space required before the open brace '{'\n" . $herecurr); } # closing brace should have a space following it when it has anything # on the line if ($line =~ /}(?!(?:,|;|\)))\S/) { - ERROR("space required after that close brace '}'\n" . $herecurr); + ERROR("SPACING", + "space required after that close brace '}'\n" . $herecurr); } # check spacing on square brackets if ($line =~ /\[\s/ && $line !~ /\[\s*$/) { - ERROR("space prohibited after that open square bracket '['\n" . $herecurr); + ERROR("SPACING", + "space prohibited after that open square bracket '['\n" . $herecurr); } if ($line =~ /\s\]/) { - ERROR("space prohibited before that close square bracket ']'\n" . $herecurr); + ERROR("SPACING", + "space prohibited before that close square bracket ']'\n" . $herecurr); } # check spacing on parentheses if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ && $line !~ /for\s*\(\s+;/) { - ERROR("space prohibited after that open parenthesis '('\n" . $herecurr); + ERROR("SPACING", + "space prohibited after that open parenthesis '('\n" . $herecurr); } if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ && $line !~ /for\s*\(.*;\s+\)/ && $line !~ /:\s+\)/) { - ERROR("space prohibited before that close parenthesis ')'\n" . $herecurr); + ERROR("SPACING", + "space prohibited before that close parenthesis ')'\n" . $herecurr); } #goto labels aren't indented, allow a single space however if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { - WARN("labels should not be indented\n" . $herecurr); + WARN("INDENTED_LABEL", + "labels should not be indented\n" . $herecurr); } # Return is not a function. @@ -2316,23 +2456,26 @@ sub process { } #print "value<$value>\n"; if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) { - ERROR("return is not a function, parentheses are not required\n" . $herecurr); + ERROR("RETURN_PARENTHESES", + "return is not a function, parentheses are not required\n" . $herecurr); } elsif ($spacing !~ /\s+/) { - ERROR("space required before the open parenthesis '('\n" . $herecurr); + ERROR("SPACING", + "space required before the open parenthesis '('\n" . $herecurr); } } # Return of what appears to be an errno should normally be -'ve if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) { my $name = $1; if ($name ne 'EOF' && $name ne 'ERROR') { - WARN("return of an errno should typically be -ve (return -$1)\n" . $herecurr); + WARN("USE_NEGATIVE_ERRNO", + "return of an errno should typically be -ve (return -$1)\n" . $herecurr); } } # Need a space before open parenthesis after if, while etc if ($line=~/\b(if|while|for|switch)\(/) { - ERROR("space required before the open parenthesis '('\n" . $herecurr); + ERROR("SPACING", "space required before the open parenthesis '('\n" . $herecurr); } # Check for illegal assignment in if conditional -- and check for trailing @@ -2360,7 +2503,8 @@ sub process { my ($s, $c) = ($stat, $cond); if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) { - ERROR("do not use assignment in if condition\n" . $herecurr); + ERROR("ASSIGN_IN_IF", + "do not use assignment in if condition\n" . $herecurr); } # Find out what is on the end of the line after the @@ -2382,7 +2526,8 @@ sub process { $stat_real = "[...]\n$stat_real"; } - ERROR("trailing statements should be on next line\n" . $herecurr . $stat_real); + ERROR("TRAILING_STATEMENTS", + "trailing statements should be on next line\n" . $herecurr . $stat_real); } } @@ -2398,7 +2543,8 @@ sub process { (?:\&\&|\|\||\)|\]) )/x) { - WARN("boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr); + WARN("HEXADECIMAL_BOOLEAN_TEST", + "boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr); } # if and else should not have general statements after it @@ -2406,12 +2552,14 @@ sub process { my $s = $1; $s =~ s/$;//g; # Remove any comments if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) { - ERROR("trailing statements should be on next line\n" . $herecurr); + ERROR("TRAILING_STATEMENTS", + "trailing statements should be on next line\n" . $herecurr); } } # if should not continue a brace if ($line =~ /}\s*if\b/) { - ERROR("trailing statements should be on next line\n" . + ERROR("TRAILING_STATEMENTS", + "trailing statements should be on next line\n" . $herecurr); } # case and default should not have general statements after them @@ -2421,14 +2569,16 @@ sub process { \s*return\s+ )/xg) { - ERROR("trailing statements should be on next line\n" . $herecurr); + ERROR("TRAILING_STATEMENTS", + "trailing statements should be on next line\n" . $herecurr); } # Check for }<nl>else {, these must be at the same # indent level to be relevant to each other. if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and $previndent == $indent) { - ERROR("else should follow close brace '}'\n" . $hereprev); + ERROR("ELSE_AFTER_BRACE", + "else should follow close brace '}'\n" . $hereprev); } if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ and @@ -2441,7 +2591,8 @@ sub process { $s =~ s/\n.*//g; if ($s =~ /^\s*;/) { - ERROR("while should follow close brace '}'\n" . $hereprev); + ERROR("WHILE_AFTER_BRACE", + "while should follow close brace '}'\n" . $hereprev); } } @@ -2454,7 +2605,8 @@ sub process { #no spaces allowed after \ in define if ($line=~/\#\s*define.*\\\s$/) { - WARN("Whitepspace after \\ makes next lines useless\n" . $herecurr); + WARN("WHITESPACE_AFTER_LINE_CONTINUATION", + "Whitepspace after \\ makes next lines useless\n" . $herecurr); } #warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line) @@ -2466,9 +2618,11 @@ sub process { $1 !~ /$allowed_asm_includes/) { if ($realfile =~ m{^arch/}) { - CHK("Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr); + CHK("ARCH_INCLUDE_LINUX", + "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr); } else { - WARN("Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr); + WARN("INCLUDE_LINUX", + "Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr); } } } @@ -2552,7 +2706,8 @@ sub process { if ($rest !~ /while\s*\(/ && $dstat !~ /$exceptions/) { - ERROR("Macros with multiple statements should be enclosed in a do - while loop\n" . "$here\n$ctx\n"); + ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE", + "Macros with multiple statements should be enclosed in a do - while loop\n" . "$here\n$ctx\n"); } } elsif ($ctx !~ /;/) { @@ -2562,7 +2717,8 @@ sub process { $dstat !~ /^\.$Ident\s*=/ && $dstat =~ /$Operators/) { - ERROR("Macros with complex values should be enclosed in parenthesis\n" . "$here\n$ctx\n"); + ERROR("COMPLEX_MACRO", + "Macros with complex values should be enclosed in parenthesis\n" . "$here\n$ctx\n"); } } } @@ -2573,7 +2729,8 @@ sub process { # ALIGN(...) # VMLINUX_SYMBOL(...) if ($realfile eq 'vmlinux.lds.h' && $line =~ /(?:(?:^|\s)$Ident\s*=|=\s*$Ident(?:\s|$))/) { - WARN("vmlinux.lds.h needs VMLINUX_SYMBOL() around C-visible symbols\n" . $herecurr); + WARN("MISSING_VMLINUX_SYMBOL", + "vmlinux.lds.h needs VMLINUX_SYMBOL() around C-visible symbols\n" . $herecurr); } # check for redundant bracing round if etc @@ -2621,7 +2778,8 @@ sub process { } } if ($seen && !$allowed) { - WARN("braces {} are not necessary for any arm of this statement\n" . $herectx); + WARN("BRACES", + "braces {} are not necessary for any arm of this statement\n" . $herectx); } } } @@ -2675,53 +2833,60 @@ sub process { $herectx .= raw_line($linenr, $n) . "\n";; } - WARN("braces {} are not necessary for single statement blocks\n" . $herectx); + WARN("BRACES", + "braces {} are not necessary for single statement blocks\n" . $herectx); } } # don't include deprecated include files (uses RAW line) for my $inc (@dep_includes) { if ($rawline =~ m@^.\s*\#\s*include\s*\<$inc>@) { - ERROR("Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n" . $herecurr); + ERROR("DEPRECATED_INCLUDE", + "Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n" . $herecurr); } } # don't use deprecated functions for my $func (@dep_functions) { if ($line =~ /\b$func\b/) { - ERROR("Don't use $func(): see Documentation/feature-removal-schedule.txt\n" . $herecurr); + ERROR("DEPRECATED_FUNCTION", + "Don't use $func(): see Documentation/feature-removal-schedule.txt\n" . $herecurr); } } # no volatiles please my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b}; if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) { - WARN("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr); - } - -# SPIN_LOCK_UNLOCKED & RW_LOCK_UNLOCKED are deprecated - if ($line =~ /\b(SPIN_LOCK_UNLOCKED|RW_LOCK_UNLOCKED)/) { - ERROR("Use of $1 is deprecated: see Documentation/spinlocks.txt\n" . $herecurr); + WARN("VOLATILE", + "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr); } # warn about #if 0 if ($line =~ /^.\s*\#\s*if\s+0\b/) { - CHK("if this code is redundant consider removing it\n" . - $herecurr); + WARN("IF_0", + "Consider removing the code enclosed by this #if 0 and its #endif\n" . $herecurr); + } + +# warn about #if 1 + if ($line =~ /^.\s*\#\s*if\s+1\b/) { + WARN("IF_1", + "Consider removing the #if 1 and its #endif\n" . $herecurr); } # check for needless kfree() checks if ($prevline =~ /\bif\s*\(([^\)]*)\)/) { my $expr = $1; if ($line =~ /\bkfree\(\Q$expr\E\);/) { - WARN("kfree(NULL) is safe this check is probably not required\n" . $hereprev); + WARN("NEEDLESS_KFREE", + "kfree(NULL) is safe this check is probably not required\n" . $hereprev); } } # check for needless usb_free_urb() checks if ($prevline =~ /\bif\s*\(([^\)]*)\)/) { my $expr = $1; if ($line =~ /\busb_free_urb\(\Q$expr\E\);/) { - WARN("usb_free_urb(NULL) is safe this check is probably not required\n" . $hereprev); + WARN("NEEDLESS_USB_FREE_URB", + "usb_free_urb(NULL) is safe this check is probably not required\n" . $hereprev); } } @@ -2729,14 +2894,16 @@ sub process { if ($line =~ /\budelay\s*\(\s*(\w+)\s*\)/) { # ignore udelay's < 10, however if (! (($1 =~ /(\d+)/) && ($1 < 10)) ) { - CHK("usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line); + CHK("USLEEP_RANGE", + "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line); } } # warn about unexpectedly long msleep's if ($line =~ /\bmsleep\s*\((\d+)\);/) { if ($1 < 20) { - WARN("msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $line); + WARN("MSLEEP", + "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $line); } } @@ -2749,7 +2916,8 @@ sub process { # warn about spacing in #ifdefs if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) { - ERROR("exactly one space required after that #$1\n" . $herecurr); + ERROR("SPACING", + "exactly one space required after that #$1\n" . $herecurr); } # check for spinlock_t definitions without a comment. @@ -2757,40 +2925,69 @@ sub process { $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) { my $which = $1; if (!ctx_has_comment($first_line, $linenr)) { - CHK("$1 definition without comment\n" . $herecurr); + CHK("UNCOMMENTED_DEFINITION", + "$1 definition without comment\n" . $herecurr); } } # check for memory barriers without a comment. if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) { if (!ctx_has_comment($first_line, $linenr)) { - CHK("memory barrier without comment\n" . $herecurr); + CHK("MEMORY_BARRIER", + "memory barrier without comment\n" . $herecurr); } } # check of hardware specific defines if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) { - CHK("architecture specific defines should be avoided\n" . $herecurr); + CHK("ARCH_DEFINES", + "architecture specific defines should be avoided\n" . $herecurr); } # Check that the storage class is at the beginning of a declaration if ($line =~ /\b$Storage\b/ && $line !~ /^.\s*$Storage\b/) { - WARN("storage class should be at the beginning of the declaration\n" . $herecurr) + WARN("STORAGE_CLASS", + "storage class should be at the beginning of the declaration\n" . $herecurr) } # check the location of the inline attribute, that it is between # storage class and type. if ($line =~ /\b$Type\s+$Inline\b/ || $line =~ /\b$Inline\s+$Storage\b/) { - ERROR("inline keyword should sit between storage class and type\n" . $herecurr); + ERROR("INLINE_LOCATION", + "inline keyword should sit between storage class and type\n" . $herecurr); } # Check for __inline__ and __inline, prefer inline if ($line =~ /\b(__inline__|__inline)\b/) { - WARN("plain inline is preferred over $1\n" . $herecurr); + WARN("INLINE", + "plain inline is preferred over $1\n" . $herecurr); } # check for sizeof(&) if ($line =~ /\bsizeof\s*\(\s*\&/) { - WARN("sizeof(& should be avoided\n" . $herecurr); + WARN("SIZEOF_ADDRESS", + "sizeof(& should be avoided\n" . $herecurr); + } + +# Check for misused memsets + if (defined $stat && $stat =~ /\bmemset\s*\((.*)\)/s) { + my $args = $1; + + # Flatten any parentheses and braces + while ($args =~ s/\([^\(\)]*\)/10/s || + $args =~ s/\{[^\{\}]*\}/10/s || + $args =~ s/\[[^\[\]]*\]/10/s) + { + } + # Extract the simplified arguments. + my ($ms_addr, $ms_val, $ms_size) = + split(/\s*,\s*/, $args); + if ($ms_size =~ /^(0x|)0$/i) { + ERROR("MEMSET", + "memset size is 3rd argument, not the second.\n" . $herecurr); + } elsif ($ms_size =~ /^(0x|)1$/i) { + WARN("MEMSET", + "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . $herecurr); + } } # check for new externs in .c files. @@ -2807,17 +3004,20 @@ sub process { if ($s =~ /^\s*;/ && $function_name ne 'uninitialized_var') { - WARN("externs should be avoided in .c files\n" . $herecurr); + WARN("AVOID_EXTERNS", + "externs should be avoided in .c files\n" . $herecurr); } if ($paren_space =~ /\n/) { - WARN("arguments for function declarations should follow identifier\n" . $herecurr); + WARN("FUNCTION_ARGUMENTS", + "arguments for function declarations should follow identifier\n" . $herecurr); } } elsif ($realfile =~ /\.c$/ && defined $stat && $stat =~ /^.\s*extern\s+/) { - WARN("externs should be avoided in .c files\n" . $herecurr); + WARN("AVOID_EXTERNS", + "externs should be avoided in .c files\n" . $herecurr); } # checks for new __setup's @@ -2825,32 +3025,38 @@ sub process { my $name = $1; if (!grep(/$name/, @setup_docs)) { - CHK("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr); + CHK("UNDOCUMENTED_SETUP", + "__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr); } } # check for pointless casting of kmalloc return if ($line =~ /\*\s*\)\s*k[czm]alloc\b/) { - WARN("unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); + WARN("UNNECESSARY_CASTS", + "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); } # check for gcc specific __FUNCTION__ if ($line =~ /__FUNCTION__/) { - WARN("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr); + WARN("USE_FUNC", + "__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr); } # check for semaphores initialized locked if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) { - WARN("consider using a completion\n" . $herecurr); + WARN("CONSIDER_COMPLETION", + "consider using a completion\n" . $herecurr); } # recommend strict_strto* over simple_strto* if ($line =~ /\bsimple_(strto.*?)\s*\(/) { - WARN("consider using strict_$1 in preference to simple_$1\n" . $herecurr); + WARN("CONSIDER_KSTRTO", + "consider using strict_$1 in preference to simple_$1\n" . $herecurr); } # check for __initcall(), use device_initcall() explicitly please if ($line =~ /^.\s*__initcall\s*\(/) { - WARN("please use device_initcall() instead of __initcall()\n" . $herecurr); + WARN("USE_DEVICE_INITCALL", + "please use device_initcall() instead of __initcall()\n" . $herecurr); } # check for various ops structs, ensure they are const. my $struct_ops = qr{acpi_dock_ops| @@ -2892,7 +3098,8 @@ sub process { wd_ops}x; if ($line !~ /\bconst\b/ && $line =~ /\bstruct\s+($struct_ops)\b/) { - WARN("struct $1 should normally be const\n" . + WARN("CONST_STRUCT", + "struct $1 should normally be const\n" . $herecurr); } @@ -2905,7 +3112,8 @@ sub process { $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ && $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/) { - WARN("usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr); + WARN("NR_CPUS", + "usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr); } # check for %L{u,d,i} in strings @@ -2914,7 +3122,8 @@ sub process { $string = substr($rawline, $-[1], $+[1] - $-[1]); $string =~ s/%%/__/g; if ($string =~ /(?<!%)%L[udi]/) { - WARN("\%Ld/%Lu are not-standard C, use %lld/%llu\n" . $herecurr); + WARN("PRINTF_L", + "\%Ld/%Lu are not-standard C, use %lld/%llu\n" . $herecurr); last; } } @@ -2922,9 +3131,11 @@ sub process { # whine mightly about in_atomic if ($line =~ /\bin_atomic\s*\(/) { if ($realfile =~ m@^drivers/@) { - ERROR("do not use in_atomic in drivers\n" . $herecurr); + ERROR("IN_ATOMIC", + "do not use in_atomic in drivers\n" . $herecurr); } elsif ($realfile !~ m@^kernel/@) { - WARN("use of in_atomic() is incorrect outside core kernel code\n" . $herecurr); + ERROR("IN_ATOMIC", + "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr); } } @@ -2934,7 +3145,8 @@ sub process { if ($realfile !~ m@^kernel/lockdep@ && $realfile !~ m@^include/linux/lockdep@ && $realfile !~ m@^drivers/base/core@) { - ERROR("lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr); + ERROR("LOCKDEP", + "lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr); } } } @@ -2958,10 +3170,12 @@ sub process { } if (!$is_patch) { - ERROR("Does not appear to be a unified-diff format patch\n"); + ERROR("NOT_UNIFIED_DIFF", + "Does not appear to be a unified-diff format patch\n"); } if ($is_patch && $chk_signoff && $signoff == 0) { - ERROR("Missing Signed-off-by: line(s)\n"); + ERROR("MISSING_SIGN_OFF", + "Missing Signed-off-by: line(s)\n"); } print report_dump(); @@ -2983,13 +3197,25 @@ sub process { } } + if (keys %ignore_type) { + print "NOTE: Ignored message types:"; + foreach my $ignore (sort keys %ignore_type) { + print " $ignore"; + } + print "\n"; + print "\n" if ($quiet == 0); + } + if ($clean == 1 && $quiet == 0) { print "$vname has no obvious style problems and is ready for submission.\n" } if ($clean == 0 && $quiet == 0) { - print "$vname has style problems, please review. If any of these errors\n"; - print "are false positives report them to the maintainer, see\n"; - print "CHECKPATCH in MAINTAINERS.\n"; + print << "EOM"; +$vname has style problems, please review. + +If any of these errors are false positives, please report +them to the maintainer, see CHECKPATCH in MAINTAINERS. +EOM } return $clean; |