From patchwork Wed Jul 20 04:20:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 72396 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp429764qga; Tue, 19 Jul 2016 21:23:23 -0700 (PDT) X-Received: by 10.66.11.234 with SMTP id t10mr71051183pab.66.1468988603672; Tue, 19 Jul 2016 21:23:23 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e7si1078843pas.120.2016.07.19.21.23.23; Tue, 19 Jul 2016 21:23:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753288AbcGTEXO (ORCPT + 29 others); Wed, 20 Jul 2016 00:23:14 -0400 Received: from alt42.smtp-out.videotron.ca ([23.233.128.29]:7035 "EHLO alt42.smtp-out.videotron.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751415AbcGTEUt (ORCPT ); Wed, 20 Jul 2016 00:20:49 -0400 Received: from yoda.home ([96.23.157.65]) by Videotron with SMTP id Pj01bVPUj6cTKPj03bgUbA; Wed, 20 Jul 2016 00:20:47 -0400 X-Authority-Analysis: v=2.1 cv=TfA2zUkh c=1 sm=1 tr=0 a=keA3yYpnlypCNW5BNWqu+w==:117 a=keA3yYpnlypCNW5BNWqu+w==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=cAmyUtKerLwA:10 a=KKAkSRfTAAAA:8 a=iZaFaP6hAAAA:8 a=45QZGJB-ShMkZFGXABgA:9 a=YswRYOTmQJmrF1GL:21 a=GrYw3dP9qZ47_9-D:21 a=cvBusfyB2V15izCimMoJ:22 a=UxayepoFF4TaDnq9WfCN:22 Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTP id CD40F2DA0522; Wed, 20 Jul 2016 00:20:45 -0400 (EDT) From: Nicolas Pitre To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Alexander Viro , David Howells , Greg Ungerer Subject: [PATCH v3 02/12] binfmt_flat: convert printk invocations to their modern form Date: Wed, 20 Jul 2016 00:20:14 -0400 Message-Id: <1468988424-32671-3-git-send-email-nicolas.pitre@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1468988424-32671-1-git-send-email-nicolas.pitre@linaro.org> References: <1468988424-32671-1-git-send-email-nicolas.pitre@linaro.org> X-CMAE-Envelope: MS4wfCJ5BqA1ah2kzJCaaCvUPMxfErW4yT2V2Oz0ENrdv5vhz32tQGLJ8YgKPwP9m0DtizUKOo6t3bSR3m4ZEXZVNRhQRxihEkPt/OyIxp6GCIOF2sYKfhB/ ltsG9ZvKeAhAXQZSZ/UWkPs9llfxIAFbZFYSYiYa9avA+DNeQlc9K6/R6WhmyU/2Se/3FcG8Tdh8DDZe10oQmub9Xp7a+/8RChGMcfCiZgmbm03jucaosg4E vxcWoukzpIG6w7jD//9Ux33Rld2mQLGzEjK8T9uUpPfBwbQnDZ8zIpprLmSY23CG1YR2ynd7bM1TnqtagQZ6bw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Nicolas Pitre --- fs/binfmt_flat.c | 118 ++++++++++++++++++++++++------------------------------- 1 file changed, 51 insertions(+), 67 deletions(-) -- 2.7.4 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c index 085059d879..36f5bb6b2c 100644 --- a/fs/binfmt_flat.c +++ b/fs/binfmt_flat.c @@ -15,6 +15,8 @@ * JAN/99 -- coded full program relocation (gerg@snapgear.com) */ +#define pr_fmt(fmt) "BINFMT_FLAT: : " fmt + #include #include #include @@ -44,16 +46,6 @@ /****************************************************************************/ -#if 0 -#define DEBUG 1 -#endif - -#ifdef DEBUG -#define DBG_FLT(a...) printk(a) -#else -#define DBG_FLT(a...) -#endif - /* * User data (data section and bss) needs to be aligned. * We pick 0x20 here because it is the max value elf2flt has always @@ -106,8 +98,8 @@ static struct linux_binfmt flat_format = { static int flat_core_dump(struct coredump_params *cprm) { - printk("Process %s:%d received signr %d and should have core dumped\n", - current->comm, current->pid, cprm->siginfo->si_signo); + pr_warning("Process %s:%d received signr %d and should have core dumped\n", + current->comm, current->pid, cprm->siginfo->si_signo); return(1); } @@ -190,17 +182,17 @@ static int decompress_exec( loff_t fpos; int ret, retval; - DBG_FLT("decompress_exec(offset=%lx,buf=%p,len=%lx)\n",offset, dst, len); + pr_debug("decompress_exec(offset=%lx,buf=%p,len=%lx)\n",offset, dst, len); memset(&strm, 0, sizeof(strm)); strm.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL); if (strm.workspace == NULL) { - DBG_FLT("binfmt_flat: no memory for decompress workspace\n"); + pr_debug("no memory for decompress workspace\n"); return -ENOMEM; } buf = kmalloc(LBUFSIZE, GFP_KERNEL); if (buf == NULL) { - DBG_FLT("binfmt_flat: no memory for read buffer\n"); + pr_debug("no memory for read buffer\n"); retval = -ENOMEM; goto out_free; } @@ -218,25 +210,25 @@ static int decompress_exec( /* Check minimum size -- gzip header */ if (ret < 10) { - DBG_FLT("binfmt_flat: file too small?\n"); + pr_debug("file too small?\n"); goto out_free_buf; } /* Check gzip magic number */ if ((buf[0] != 037) || ((buf[1] != 0213) && (buf[1] != 0236))) { - DBG_FLT("binfmt_flat: unknown compression magic?\n"); + pr_debug("unknown compression magic?\n"); goto out_free_buf; } /* Check gzip method */ if (buf[2] != 8) { - DBG_FLT("binfmt_flat: unknown compression method?\n"); + pr_debug("unknown compression method?\n"); goto out_free_buf; } /* Check gzip flags */ if ((buf[3] & ENCRYPTED) || (buf[3] & CONTINUATION) || (buf[3] & RESERVED)) { - DBG_FLT("binfmt_flat: unknown flags?\n"); + pr_debug("unknown flags?\n"); goto out_free_buf; } @@ -244,7 +236,7 @@ static int decompress_exec( if (buf[3] & EXTRA_FIELD) { ret += 2 + buf[10] + (buf[11] << 8); if (unlikely(LBUFSIZE <= ret)) { - DBG_FLT("binfmt_flat: buffer overflow (EXTRA)?\n"); + pr_debug("buffer overflow (EXTRA)?\n"); goto out_free_buf; } } @@ -252,7 +244,7 @@ static int decompress_exec( while (ret < LBUFSIZE && buf[ret++] != 0) ; if (unlikely(LBUFSIZE == ret)) { - DBG_FLT("binfmt_flat: buffer overflow (ORIG_NAME)?\n"); + pr_debug("buffer overflow (ORIG_NAME)?\n"); goto out_free_buf; } } @@ -260,7 +252,7 @@ static int decompress_exec( while (ret < LBUFSIZE && buf[ret++] != 0) ; if (unlikely(LBUFSIZE == ret)) { - DBG_FLT("binfmt_flat: buffer overflow (COMMENT)?\n"); + pr_debug("buffer overflow (COMMENT)?\n"); goto out_free_buf; } } @@ -273,7 +265,7 @@ static int decompress_exec( strm.total_out = 0; if (zlib_inflateInit2(&strm, -MAX_WBITS) != Z_OK) { - DBG_FLT("binfmt_flat: zlib init failed?\n"); + pr_debug("zlib init failed?\n"); goto out_free_buf; } @@ -290,7 +282,7 @@ static int decompress_exec( } if (ret < 0) { - DBG_FLT("binfmt_flat: decompression failed (%d), %s\n", + pr_debug("decompression failed (%d), %s\n", ret, strm.msg); goto out_zlib; } @@ -327,24 +319,23 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp) r &= 0x00ffffff; /* Trim ID off here */ } if (id >= MAX_SHARED_LIBS) { - printk("BINFMT_FLAT: reference 0x%x to shared library %d", - (unsigned) r, id); + pr_err("reference 0x%lx to shared library %d", r, id); goto failed; } if (curid != id) { if (internalp) { - printk("BINFMT_FLAT: reloc address 0x%x not in same module " - "(%d != %d)", (unsigned) r, curid, id); + pr_err("reloc address 0x%lx not in same module " + "(%d != %d)", r, curid, id); goto failed; } else if ( ! p->lib_list[id].loaded && load_flat_shared_library(id, p) < 0) { - printk("BINFMT_FLAT: failed to load library %d", id); + pr_err("failed to load library %d", id); goto failed; } /* Check versioning information (i.e. time stamps) */ if (p->lib_list[id].build_date && p->lib_list[curid].build_date && p->lib_list[curid].build_date < p->lib_list[id].build_date) { - printk("BINFMT_FLAT: library %d is younger than %d", id, curid); + pr_err("library %d is younger than %d", id, curid); goto failed; } } @@ -358,7 +349,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp) text_len = p->lib_list[id].text_len; if (!flat_reloc_valid(r, start_brk - start_data + text_len)) { - printk("BINFMT_FLAT: reloc outside program 0x%lx (0 - 0x%lx/0x%lx)", + pr_err("reloc outside program 0x%lx (0 - 0x%lx/0x%lx)", r, start_brk-start_data+text_len, text_len); goto failed; } @@ -372,7 +363,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp) return(addr); failed: - printk(", killing %s!\n", current->comm); + pr_cont(", killing %s!\n", current->comm); send_sig(SIGSEGV, current, 0); return RELOC_FAILED; @@ -382,9 +373,7 @@ failed: static void old_reloc(unsigned long rl) { -#ifdef DEBUG static const char *segment[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" }; -#endif flat_v2_reloc_t r; unsigned long *ptr; @@ -395,11 +384,9 @@ static void old_reloc(unsigned long rl) ptr = (unsigned long *) (current->mm->start_data + r.reloc.offset); #endif -#ifdef DEBUG - printk("Relocation of variable at DATASEG+%x " - "(address %p, currently %lx) into segment %s\n", - r.reloc.offset, ptr, *ptr, segment[r.reloc.type]); -#endif + pr_debug("Relocation of variable at DATASEG+%x " + "(address %p, currently %lx) into segment %s\n", + r.reloc.offset, ptr, *ptr, segment[r.reloc.type]); switch (r.reloc.type) { case OLD_FLAT_RELOC_TYPE_TEXT: @@ -412,13 +399,11 @@ static void old_reloc(unsigned long rl) *ptr += current->mm->end_data; break; default: - printk("BINFMT_FLAT: Unknown relocation type=%x\n", r.reloc.type); + pr_err("Unknown relocation type=%x\n", r.reloc.type); break; } -#ifdef DEBUG - printk("Relocation became %lx\n", *ptr); -#endif + pr_debug("Relocation became %lx\n", *ptr); } /****************************************************************************/ @@ -467,20 +452,19 @@ static int load_flat_file(struct linux_binprm * bprm, } if (flags & FLAT_FLAG_KTRACE) - printk("BINFMT_FLAT: Loading file: %s\n", bprm->filename); + pr_info("Loading file: %s\n", bprm->filename); if (rev != FLAT_VERSION && rev != OLD_FLAT_VERSION) { - printk("BINFMT_FLAT: bad flat file version 0x%x (supported " - "0x%lx and 0x%lx)\n", - rev, FLAT_VERSION, OLD_FLAT_VERSION); + pr_err("bad flat file version 0x%x (supported 0x%lx and 0x%lx)\n", + rev, FLAT_VERSION, OLD_FLAT_VERSION); ret = -ENOEXEC; goto err; } /* Don't allow old format executables to use shared libraries */ if (rev == OLD_FLAT_VERSION && id != 0) { - printk("BINFMT_FLAT: shared libraries are not available before rev 0x%lx\n", - FLAT_VERSION); + pr_err("shared libraries are not available before rev 0x%lx\n", + FLAT_VERSION); ret = -ENOEXEC; goto err; } @@ -494,7 +478,7 @@ static int load_flat_file(struct linux_binprm * bprm, #ifndef CONFIG_BINFMT_ZFLAT if (flags & (FLAT_FLAG_GZIP|FLAT_FLAG_GZDATA)) { - printk("Support for ZFLAT executables is not enabled.\n"); + pr_err("Support for ZFLAT executables is not enabled.\n"); ret = -ENOEXEC; goto err; } @@ -540,7 +524,7 @@ static int load_flat_file(struct linux_binprm * bprm, * this should give us a ROM ptr, but if it doesn't we don't * really care */ - DBG_FLT("BINFMT_FLAT: ROM mapping of file (we hope)\n"); + pr_debug("ROM mapping of file (we hope)\n"); textpos = vm_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_EXECUTABLE, 0); @@ -548,7 +532,7 @@ static int load_flat_file(struct linux_binprm * bprm, ret = textpos; if (!textpos) ret = -ENOMEM; - printk("Unable to mmap process text, errno %d\n", ret); + pr_err("Unable to mmap process text, errno %d\n", ret); goto err; } @@ -561,7 +545,7 @@ static int load_flat_file(struct linux_binprm * bprm, ret = realdatastart; if (!realdatastart) ret = -ENOMEM; - printk("Unable to allocate RAM for process data, " + pr_err("Unable to allocate RAM for process data, " "errno %d\n", ret); vm_munmap(textpos, text_len); goto err; @@ -570,8 +554,8 @@ static int load_flat_file(struct linux_binprm * bprm, MAX_SHARED_LIBS * sizeof(unsigned long), FLAT_DATA_ALIGN); - DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%ld bytes): %lx\n", - data_len + bss_len + stack_len, datapos); + pr_debug("Allocated data+bss+stack (%ld bytes): %lx\n", + data_len + bss_len + stack_len, datapos); fpos = ntohl(hdr->data_start); #ifdef CONFIG_BINFMT_ZFLAT @@ -586,7 +570,7 @@ static int load_flat_file(struct linux_binprm * bprm, } if (IS_ERR_VALUE(result)) { ret = result; - printk("Unable to read data+bss, errno %d\n", ret); + pr_err("Unable to read data+bss, errno %d\n", ret); vm_munmap(textpos, text_len); vm_munmap(realdatastart, len); goto err; @@ -607,7 +591,7 @@ static int load_flat_file(struct linux_binprm * bprm, ret = textpos; if (!textpos) ret = -ENOMEM; - printk("Unable to allocate RAM for process text/data, " + pr_err("Unable to allocate RAM for process text/data, " "errno %d\n", ret); goto err; } @@ -650,7 +634,7 @@ static int load_flat_file(struct linux_binprm * bprm, } if (IS_ERR_VALUE(result)) { ret = result; - printk("Unable to read code+data+bss, errno %d\n", ret); + pr_err("Unable to read code+data+bss, errno %d\n", ret); vm_munmap(textpos, text_len + data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long)); goto err; @@ -680,12 +664,12 @@ static int load_flat_file(struct linux_binprm * bprm, } if (flags & FLAT_FLAG_KTRACE) { - printk("Mapping is %lx, Entry point is %x, data_start is %x\n", - textpos, 0x00ffffff&ntohl(hdr->entry), ntohl(hdr->data_start)); - printk("%s %s: TEXT=%lx-%lx DATA=%lx-%lx BSS=%lx-%lx\n", - id ? "Lib" : "Load", bprm->filename, - start_code, end_code, datapos, datapos + data_len, - datapos + data_len, (datapos + data_len + bss_len + 3) & ~3); + pr_info("Mapping is %lx, Entry point is %x, data_start is %x\n", + textpos, 0x00ffffff&ntohl(hdr->entry), ntohl(hdr->data_start)); + pr_info("%s %s: TEXT=%lx-%lx DATA=%lx-%lx BSS=%lx-%lx\n", + id ? "Lib" : "Load", bprm->filename, + start_code, end_code, datapos, datapos + data_len, + datapos + data_len, (datapos + data_len + bss_len + 3) & ~3); } /* Store the current module values into the global library structure */ @@ -893,7 +877,7 @@ static int load_flat_binary(struct linux_binprm * bprm) set_binfmt(&flat_format); p = ((current->mm->context.end_brk + stack_len + 3) & ~3) - 4; - DBG_FLT("p=%lx\n", p); + pr_debug("p=%lx\n", p); /* copy the arg pages onto the stack, this could be more efficient :-) */ for (i = TOP_OF_ARGS - 1; i >= bprm->p; i--) @@ -925,8 +909,8 @@ static int load_flat_binary(struct linux_binprm * bprm) FLAT_PLAT_INIT(regs); #endif - DBG_FLT("start_thread(regs=0x%p, entry=0x%lx, start_stack=0x%lx)\n", - regs, start_addr, current->mm->start_stack); + pr_debug("start_thread(regs=0x%p, entry=0x%lx, start_stack=0x%lx)\n", + regs, start_addr, current->mm->start_stack); start_thread(regs, start_addr, current->mm->start_stack); return 0;