Thread (71 messages) 71 messages, 6 authors, 2020-04-02

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

From: Jinpu Wang <jinpu.wang@cloud.ionos.com>
Date: 2020-03-31 15:32:15
Also in: linux-rdma

snip
quoted
quoted
+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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help