Re: [PATCH v11 21/26] block/rnbd: server: main functionality

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

 



snip
> >
> > > +static char *rnbd_srv_get_full_path(struct rnbd_srv_session *srv_sess,
> > > +                                  const char *dev_name)
> > > +{
> > > +     char *full_path;
> > > +     char *a, *b;
> > > +
> > > +     full_path = kmalloc(PATH_MAX, GFP_KERNEL);
> > > +     if (!full_path)
> > > +             return ERR_PTR(-ENOMEM);
> > > +
> > > +     /*
> > > +      * Replace %SESSNAME% with a real session name in order to
> > > +      * create device namespace.
> > > +      */
> > > +     a = strnstr(dev_search_path, "%SESSNAME%", sizeof(dev_search_path));
> > > +     if (a) {
> > > +             int len = a - dev_search_path;
> > > +
> > > +             len = snprintf(full_path, PATH_MAX, "%.*s/%s/%s", len,
> > > +                            dev_search_path, srv_sess->sessname, dev_name);
> > > +             if (len >= PATH_MAX) {
> > > +                     pr_err("Tooooo looong path: %s, %s, %s\n",
> > > +                            dev_search_path, srv_sess->sessname, dev_name);
> > > +                     kfree(full_path);
> > > +                     return ERR_PTR(-EINVAL);
> > > +             }
> > > +     } else {
> > > +             snprintf(full_path, PATH_MAX, "%s/%s",
> > > +                      dev_search_path, dev_name);
> > > +     }
> >
> > Has it been considered to use kasprintf() instead of kmalloc() + snprintf()?

I tried to convert to kasprintf, but it doesn't save line of code or
nor looks cleaner, I will keep as it is.

Thanks



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux