From patchwork Wed Jul 20 04:20:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 72394 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp429546qga; Tue, 19 Jul 2016 21:22:40 -0700 (PDT) X-Received: by 10.66.189.199 with SMTP id gk7mr72285178pac.158.1468988560096; Tue, 19 Jul 2016 21:22:40 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y67si1053306pfy.250.2016.07.19.21.22.39; Tue, 19 Jul 2016 21:22:40 -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 S1752995AbcGTEWa (ORCPT + 29 others); Wed, 20 Jul 2016 00:22:30 -0400 Received: from alt13.smtp-out.videotron.ca ([135.19.0.26]:4925 "EHLO alt12.smtp-out.videotron.ca" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751499AbcGTEUu (ORCPT ); Wed, 20 Jul 2016 00:20:50 -0400 Received: from yoda.home ([96.23.157.65]) by Videotron with SMTP id Pj01beuXuq3HFPj02b3PpL; Wed, 20 Jul 2016 00:20:48 -0400 X-Authority-Analysis: v=2.1 cv=Q9lym9Ca 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=tBb2bbeoAAAA:8 a=seqZTMgDHYfb_UfPyN0A:9 a=HQKDzIMO3WkG1IPy:21 a=98gU4DpDWQah-0mr:21 a=cvBusfyB2V15izCimMoJ:22 a=Oj-tNtZlA1e06AYgeCfH:22 Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTP id AAE052DA04C9; 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 01/12] binfmt_flat: assorted cleanups Date: Wed, 20 Jul 2016 00:20:13 -0400 Message-Id: <1468988424-32671-2-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: MS4wfDhXO2v9kzEe8NJFFsN2cN/SPs7IjuBnEdlFbEHT1RwR2wMD56qK6pMJ/MfpeLFLVEo/ZVjuCA1PMRIH40grUmi/wI3fbs/yTk9b0lnj1Z7FRSWiNRcz cpkhZvRPb7nZl3/qieKha2I3uIGaKoQkqYy1hIOBafdpkXCh/0HvFIF1TNNhr049EqAJtaFP58b1nTzz289PxNuyCG4kA0T3s5Ay0KWLBJ+asKvLeiMo5YYt GtsH7ceblBdG/0UGLkU1PRjl1ORNHcUul+0CkPUq0Dq26fgCFG32ZMxnkDAJ7ymaNtDw74OyCV0OUsBGsf78Bg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Remove excessive casts, do some code grouping, etc. No functional changes. Signed-off-by: Nicolas Pitre Reviewed-by: Greg Ungerer --- fs/binfmt_flat.c | 118 ++++++++++++++++++++++++++----------------------------- 1 file changed, 56 insertions(+), 62 deletions(-) -- 2.7.4 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c index caf9e39bb8..085059d879 100644 --- a/fs/binfmt_flat.c +++ b/fs/binfmt_flat.c @@ -80,7 +80,7 @@ struct lib_info { unsigned long text_len; /* Length of text segment */ unsigned long entry; /* Start address for this module */ unsigned long build_date; /* When this one was compiled */ - short loaded; /* Has this library been loaded? */ + bool loaded; /* Has this library been loaded? */ } lib_list[MAX_SHARED_LIBS]; }; @@ -107,7 +107,7 @@ 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, (int) cprm->siginfo->si_signo); + current->comm, current->pid, cprm->siginfo->si_signo); return(1); } @@ -190,7 +190,7 @@ static int decompress_exec( loff_t fpos; int ret, retval; - DBG_FLT("decompress_exec(offset=%x,buf=%x,len=%x)\n",(int)offset, (int)dst, (int)len); + DBG_FLT("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); @@ -358,8 +358,8 @@ 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%x (0 - 0x%x/0x%x)", - (int) r,(int)(start_brk-start_data+text_len),(int)text_len); + printk("BINFMT_FLAT: reloc outside program 0x%lx (0 - 0x%lx/0x%lx)", + r, start_brk-start_data+text_len, text_len); goto failed; } @@ -383,7 +383,7 @@ failed: static void old_reloc(unsigned long rl) { #ifdef DEBUG - char *segment[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" }; + static const char *segment[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" }; #endif flat_v2_reloc_t r; unsigned long *ptr; @@ -397,8 +397,8 @@ static void old_reloc(unsigned long rl) #ifdef DEBUG printk("Relocation of variable at DATASEG+%x " - "(address %p, currently %x) into segment %s\n", - r.reloc.offset, ptr, (int)*ptr, segment[r.reloc.type]); + "(address %p, currently %lx) into segment %s\n", + r.reloc.offset, ptr, *ptr, segment[r.reloc.type]); #endif switch (r.reloc.type) { @@ -417,7 +417,7 @@ static void old_reloc(unsigned long rl) } #ifdef DEBUG - printk("Relocation became %x\n", (int)*ptr); + printk("Relocation became %lx\n", *ptr); #endif } @@ -427,17 +427,15 @@ static int load_flat_file(struct linux_binprm * bprm, struct lib_info *libinfo, int id, unsigned long *extra_stack) { struct flat_hdr * hdr; - unsigned long textpos = 0, datapos = 0, result; - unsigned long realdatastart = 0; - unsigned long text_len, data_len, bss_len, stack_len, flags; - unsigned long full_data; - unsigned long len, memp = 0; - unsigned long memp_size, extra, rlim; - unsigned long *reloc = 0, *rp; + unsigned long textpos, datapos, realdatastart; + unsigned long text_len, data_len, bss_len, stack_len, full_data, flags; + unsigned long len, memp, memp_size, extra, rlim; + unsigned long *reloc, *rp; struct inode *inode; - int i, rev, relocs = 0; + int i, rev, relocs; loff_t fpos; unsigned long start_code, end_code; + ssize_t result; int ret; hdr = ((struct flat_hdr *) bprm->buf); /* exec-header */ @@ -481,8 +479,8 @@ static int load_flat_file(struct linux_binprm * bprm, /* 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%x\n", - (int) FLAT_VERSION); + printk("BINFMT_FLAT: shared libraries are not available before rev 0x%lx\n", + FLAT_VERSION); ret = -ENOEXEC; goto err; } @@ -517,11 +515,9 @@ static int load_flat_file(struct linux_binprm * bprm, /* Flush all traces of the currently running executable */ if (id == 0) { - result = flush_old_exec(bprm); - if (result) { - ret = result; + ret = flush_old_exec(bprm); + if (ret) goto err; - } /* OK, This is the point of no return */ set_personality(PER_LINUX_32BIT); @@ -549,33 +545,33 @@ static int load_flat_file(struct linux_binprm * bprm, textpos = vm_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_EXECUTABLE, 0); if (!textpos || IS_ERR_VALUE(textpos)) { - if (!textpos) - textpos = (unsigned long) -ENOMEM; - printk("Unable to mmap process text, errno %d\n", (int)-textpos); ret = textpos; + if (!textpos) + ret = -ENOMEM; + printk("Unable to mmap process text, errno %d\n", ret); goto err; } len = data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long); len = PAGE_ALIGN(len); - realdatastart = vm_mmap(0, 0, len, + realdatastart = vm_mmap(NULL, 0, len, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 0); if (realdatastart == 0 || IS_ERR_VALUE(realdatastart)) { + ret = realdatastart; if (!realdatastart) - realdatastart = (unsigned long) -ENOMEM; - printk("Unable to allocate RAM for process data, errno %d\n", - (int)-realdatastart); + ret = -ENOMEM; + printk("Unable to allocate RAM for process data, " + "errno %d\n", ret); vm_munmap(textpos, text_len); - ret = realdatastart; goto err; } datapos = ALIGN(realdatastart + MAX_SHARED_LIBS * sizeof(unsigned long), FLAT_DATA_ALIGN); - DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%d bytes): %x\n", - (int)(data_len + bss_len + stack_len), (int)datapos); + DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%ld bytes): %lx\n", + data_len + bss_len + stack_len, datapos); fpos = ntohl(hdr->data_start); #ifdef CONFIG_BINFMT_ZFLAT @@ -589,29 +585,30 @@ static int load_flat_file(struct linux_binprm * bprm, full_data); } if (IS_ERR_VALUE(result)) { - printk("Unable to read data+bss, errno %d\n", (int)-result); + ret = result; + printk("Unable to read data+bss, errno %d\n", ret); vm_munmap(textpos, text_len); vm_munmap(realdatastart, len); - ret = result; goto err; } - reloc = (unsigned long *) (datapos+(ntohl(hdr->reloc_start)-text_len)); + reloc = (unsigned long *) + (datapos + (ntohl(hdr->reloc_start) - text_len)); memp = realdatastart; memp_size = len; } else { len = text_len + data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long); len = PAGE_ALIGN(len); - textpos = vm_mmap(0, 0, len, + textpos = vm_mmap(NULL, 0, len, PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE, 0); if (!textpos || IS_ERR_VALUE(textpos)) { - if (!textpos) - textpos = (unsigned long) -ENOMEM; - printk("Unable to allocate RAM for process text/data, errno %d\n", - (int)-textpos); ret = textpos; + if (!textpos) + ret = -ENOMEM; + printk("Unable to allocate RAM for process text/data, " + "errno %d\n", ret); goto err; } @@ -652,21 +649,19 @@ static int load_flat_file(struct linux_binprm * bprm, full_data); } if (IS_ERR_VALUE(result)) { - printk("Unable to read code+data+bss, errno %d\n",(int)-result); + ret = result; + printk("Unable to read code+data+bss, errno %d\n", ret); vm_munmap(textpos, text_len + data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long)); - ret = result; goto err; } } - if (flags & FLAT_FLAG_KTRACE) - printk("Mapping is %x, Entry point is %x, data_start is %x\n", - (int)textpos, 0x00ffffff&ntohl(hdr->entry), ntohl(hdr->data_start)); - - /* The main program needs a little extra setup in the task structure */ start_code = textpos + sizeof (struct flat_hdr); end_code = textpos + text_len; + text_len -= sizeof(struct flat_hdr); /* the real code len */ + + /* The main program needs a little extra setup in the task structure */ if (id == 0) { current->mm->start_code = start_code; current->mm->end_code = end_code; @@ -684,16 +679,14 @@ static int load_flat_file(struct linux_binprm * bprm, current->mm->context.end_brk = memp + memp_size - stack_len; } - if (flags & FLAT_FLAG_KTRACE) - printk("%s %s: TEXT=%x-%x DATA=%x-%x BSS=%x-%x\n", - id ? "Lib" : "Load", bprm->filename, - (int) start_code, (int) end_code, - (int) datapos, - (int) (datapos + data_len), - (int) (datapos + data_len), - (int) (((datapos + data_len + bss_len) + 3) & ~3)); - - text_len -= sizeof(struct flat_hdr); /* the real code len */ + 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); + } /* Store the current module values into the global library structure */ libinfo->lib_list[id].start_code = start_code; @@ -869,6 +862,7 @@ static int load_flat_binary(struct linux_binprm * bprm) int i, j; memset(&libinfo, 0, sizeof(libinfo)); + /* * We have to add the size of our arguments to our stack size * otherwise it's too easy for users to create stack overflows @@ -899,7 +893,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=%x\n", (int)p); + DBG_FLT("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--) @@ -930,9 +924,9 @@ static int load_flat_binary(struct linux_binprm * bprm) #ifdef FLAT_PLAT_INIT FLAT_PLAT_INIT(regs); #endif - DBG_FLT("start_thread(regs=0x%x, entry=0x%x, start_stack=0x%x)\n", - (int)regs, (int)start_addr, (int)current->mm->start_stack); - + + DBG_FLT("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;