Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Simplify error path.



details:   https://anonhg.NetBSD.org/src/rev/4bdf103b310b
branches:  trunk
changeset: 793648:4bdf103b310b
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Feb 22 07:53:16 2014 +0000

description:
Simplify error path.

ok christos@

diffstat:

 sys/kern/exec_elf.c |  75 ++++++++++++++++++++++------------------------------
 1 files changed, 32 insertions(+), 43 deletions(-)

diffs (139 lines):

diff -r 65e07a336a8d -r 4bdf103b310b sys/kern/exec_elf.c
--- a/sys/kern/exec_elf.c       Fri Feb 21 22:33:08 2014 +0000
+++ b/sys/kern/exec_elf.c       Sat Feb 22 07:53:16 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exec_elf.c,v 1.60 2014/02/21 07:47:02 maxv Exp $       */
+/*     $NetBSD: exec_elf.c,v 1.61 2014/02/22 07:53:16 maxv Exp $       */
 
 /*-
  * Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.60 2014/02/21 07:47:02 maxv Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.61 2014/02/22 07:53:16 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pax.h"
@@ -921,9 +921,7 @@
 
                switch (np->n_type) {
                case ELF_NOTE_TYPE_NETBSD_TAG:
-                       /*
-                        * It is us
-                        */
+                       /* It is us */
                        if (np->n_namesz == ELF_NOTE_NETBSD_NAMESZ &&
                            np->n_descsz == ELF_NOTE_NETBSD_DESCSZ &&
                            memcmp(ndata, ELF_NOTE_NETBSD_NAME,
@@ -934,52 +932,32 @@
                                isnetbsd = 1;
                                break;
                        }
+
                        /*
-                        * Ignore SuSE tags
+                        * Ignore SuSE tags; SuSE's n_type is the same as NetBSD's
+                        * one.
                         */
                        if (np->n_namesz == ELF_NOTE_SUSE_NAMESZ &&
                            memcmp(ndata, ELF_NOTE_SUSE_NAME,
                            ELF_NOTE_SUSE_NAMESZ) == 0)
                                break;
-                       /*
-                        * Dunno, warn for diagnostic
-                        */
+
                        goto bad;
 
                case ELF_NOTE_TYPE_PAX_TAG:
-                       if (np->n_namesz != ELF_NOTE_PAX_NAMESZ ||
-                           np->n_descsz != ELF_NOTE_PAX_DESCSZ ||
+                       if (np->n_namesz == ELF_NOTE_PAX_NAMESZ &&
+                           np->n_descsz == ELF_NOTE_PAX_DESCSZ &&
                            memcmp(ndata, ELF_NOTE_PAX_NAME,
-                           ELF_NOTE_PAX_NAMESZ)) {
-bad:
-#ifdef DIAGNOSTIC
-                       {
-                               /*
-                                * Ignore GNU tags
-                                */
-                               if (np->n_namesz == ELF_NOTE_GNU_NAMESZ &&
-                                   memcmp(ndata, ELF_NOTE_GNU_NAME,
-                                   ELF_NOTE_GNU_NAMESZ) == 0)
-                                   break;
-
-                               int ns = MIN(np->n_namesz, shp->sh_size - sizeof(*np));
-                               printf("%s: Unknown elf note type %d: "
-                                   "[namesz=%d, descsz=%d name=%*.*s]\n",
-                                   epp->ep_kname, np->n_type, np->n_namesz,
-                                   np->n_descsz, ns, ns, ndata);
+                           ELF_NOTE_PAX_NAMESZ) == 0) {
+                               memcpy(&epp->ep_pax_flags,
+                                   ndata + roundup(ELF_NOTE_PAX_NAMESZ, 4),
+                                   sizeof(epp->ep_pax_flags));
+                               break;
                        }
-#endif
-                               continue;
-                       }
-                       (void)memcpy(&epp->ep_pax_flags,
-                           ndata + roundup(ELF_NOTE_PAX_NAMESZ, 4),
-                           sizeof(epp->ep_pax_flags));
-                       break;
+                       goto bad;
 
                case ELF_NOTE_TYPE_MARCH_TAG:
-                       /*
-                        * Copy the machine arch into the package.
-                        */
+                       /* Copy the machine arch into the package. */
                        if (np->n_namesz == ELF_NOTE_MARCH_NAMESZ
                            && memcmp(ndata, ELF_NOTE_MARCH_NAME,
                                    ELF_NOTE_MARCH_NAMESZ) == 0) {
@@ -988,10 +966,10 @@
                                    sizeof(epp->ep_machine_arch));
                                break;
                        }
+                       goto bad;
+
                case ELF_NOTE_TYPE_MCMODEL_TAG:
-                       /*
-                        * arch specific check for code model
-                        */
+                       /* arch specific check for code model */
 #ifdef ELF_MD_MCMODEL_CHECK
                        if (np->n_namesz == ELF_NOTE_MCMODEL_NAMESZ
                            && memcmp(ndata, ELF_NOTE_MCMODEL_NAME,
@@ -1001,6 +979,7 @@
                                    np->n_descsz);
                                break;
                        }
+                       goto bad;
 #endif
                        break;
 
@@ -1008,9 +987,19 @@
                        break;
 
                default:
+bad:
 #ifdef DIAGNOSTIC
-                       printf("%s: unknown note type %d\n", epp->ep_kname,
-                           np->n_type);
+                       /* Ignore GNU tags */
+                       if (np->n_namesz == ELF_NOTE_GNU_NAMESZ &&
+                           memcmp(ndata, ELF_NOTE_GNU_NAME,
+                           ELF_NOTE_GNU_NAMESZ) == 0)
+                           break;
+
+                       int ns = MIN(np->n_namesz, shp->sh_size - sizeof(*np));
+                       printf("%s: Unknown elf note type %d: "
+                           "[namesz=%d, descsz=%d name=%*.*s]\n",
+                           epp->ep_kname, np->n_type, np->n_namesz,
+                           np->n_descsz, ns, ns, ndata);
 #endif
                        break;
                }



Home | Main Index | Thread Index | Old Index