tech-kern archive

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

Re: Fix netbsd32's getfh()



On Jun 26,  4:30pm, max%M00nBSD.net@localhost (Maxime Villard) wrote:
-- Subject: Re: Fix netbsd32's getfh()

| I guess it's ok now?

Yes, that looks fine. But why:
        if (error != 0)
instead of:
        if (error)

I think that most code in the tree uses the second form.

christos
| 
| Index: netbsd32_netbsd.c
| ===================================================================
| RCS file: /cvsroot/src/sys/compat/netbsd32/netbsd32_netbsd.c,v
| retrieving revision 1.190
| diff -u -r1.190 netbsd32_netbsd.c
| --- netbsd32_netbsd.c 22 Jun 2014 19:09:39 -0000      1.190
| +++ netbsd32_netbsd.c 26 Jun 2014 14:21:24 -0000
| @@ -1302,7 +1302,7 @@
|       int error;
|       struct pathbuf *pb;
|       struct nameidata nd;
| -     netbsd32_size_t sz32;
| +     netbsd32_size_t usz32, sz32;
|       size_t sz;
|  
|       /*
| @@ -1312,7 +1312,6 @@
|           0, NULL, NULL, NULL);
|       if (error)
|               return (error);
| -     fh = NULL;
|  
|       error = pathbuf_copyin(SCARG_P32(uap, fname), &pb);
|       if (error) {
| @@ -1328,30 +1327,29 @@
|       vp = nd.ni_vp;
|       pathbuf_destroy(pb);
|  
| -     error = copyin(SCARG_P32(uap, fh_size), &sz32,
| -         sizeof(netbsd32_size_t));
| -     if (error) {
| -             vput(vp);
| +     error = vfs_composefh_alloc(vp, &fh);
| +     vput(vp);
| +     if (error != 0) {
|               return error;
|       }
| -     fh = kmem_alloc(sz32, KM_SLEEP);
| -     if (fh == NULL) 
| -             return EINVAL;
| -     sz = sz32;
| -     error = vfs_composefh(vp, fh, &sz);
| -     vput(vp);
| +     error = copyin(SCARG_P32(uap, fh_size), &usz32, sizeof(usz32));
| +     if (error != 0) {
| +             goto out;
| +     }
| +     sz = FHANDLE_SIZE(fh);
| +     sz32 = sz;
|  
| -     if (error == 0) {
| -             const netbsd32_size_t nsz32 = sz;
| -             error = copyout(&nsz32, SCARG_P32(uap, fh_size),
| -                 sizeof(netbsd32_size_t));
| -             if (!error) {
| -                     error = copyout(fh, SCARG_P32(uap, fhp), sz);
| -             }
| -     } else if (error == E2BIG) {
| -             error = copyout(&sz, SCARG_P32(uap, fh_size), sizeof(size_t));
| +     error = copyout(&sz32, SCARG_P32(uap, fh_size), sizeof(sz32));
| +     if (error != 0) {
| +             goto out;
| +     }
| +     if (usz32 >= sz32) {
| +             error = copyout(fh, SCARG_P32(uap, fhp), sz);
| +     } else {
| +             error = E2BIG;
|       }
| -     kmem_free(fh, sz32);
| +out:
| +     vfs_composefh_free(fh);
|       return (error);
|  }
|  
-- End of excerpt from Maxime Villard




Home | Main Index | Thread Index | Old Index