Author: ae
Date: Thu Jan 23 20:25:38 2014
New Revision: 261089
URL: http://svnweb.freebsd.org/changeset/base/261089

Log:
  Remove another unneeded NULL check from geom_alloc_copyin().
  Do copyout in case of gctl version mismatch and fix sbuf leak in
  g_ctl_ioctl_ctl().
  
  MFC after:    1 week

Modified:
  head/sys/geom/geom_ctl.c

Modified: head/sys/geom/geom_ctl.c
==============================================================================
--- head/sys/geom/geom_ctl.c    Thu Jan 23 20:21:39 2014        (r261088)
+++ head/sys/geom/geom_ctl.c    Thu Jan 23 20:25:38 2014        (r261089)
@@ -126,8 +126,7 @@ geom_alloc_copyin(struct gctl_req *req, 
        req->nerror = copyin(uaddr, ptr, len);
        if (!req->nerror)
                return (ptr);
-       if (ptr != NULL)
-               g_free(ptr);
+       g_free(ptr);
        return (NULL);
 }
 
@@ -463,30 +462,31 @@ g_ctl_ioctl_ctl(struct cdev *dev, u_long
 
        req = (void *)data;
        req->nerror = 0;
-       req->serror = sbuf_new_auto();
        /* It is an error if we cannot return an error text */
        if (req->lerror < 2)
                return (EINVAL);
        if (!useracc(req->error, req->lerror, VM_PROT_WRITE))
                return (EINVAL);
 
+       req->serror = sbuf_new_auto();
        /* Check the version */
-       if (req->version != GCTL_VERSION)
-               return (gctl_error(req,
-                   "kernel and libgeom version mismatch."));
-       
-       /* Get things on board */
-       gctl_copyin(req);
-
-       if (g_debugflags & G_F_CTLDUMP)
-               gctl_dump(req);
-
-       if (!req->nerror) {
-               g_waitfor_event(g_ctl_req, req, M_WAITOK, NULL);
-               gctl_copyout(req);
+       if (req->version != GCTL_VERSION) {
+               gctl_error(req, "kernel and libgeom version mismatch.");
+               req->arg = NULL;
+       } else {
+               /* Get things on board */
+               gctl_copyin(req);
+
+               if (g_debugflags & G_F_CTLDUMP)
+                       gctl_dump(req);
+
+               if (!req->nerror) {
+                       g_waitfor_event(g_ctl_req, req, M_WAITOK, NULL);
+                       gctl_copyout(req);
+               }
        }
        if (sbuf_done(req->serror)) {
-               req->nerror = copyout(sbuf_data(req->serror), req->error,
+               copyout(sbuf_data(req->serror), req->error,
                    imin(req->lerror, sbuf_len(req->serror) + 1));
        }
 
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to