On 6/29/2015 8:40 PM, Jason Gunthorpe wrote:
On Sun, Jun 28, 2015 at 05:33:04PM +0300, Yishai Hadas wrote:

You are wrong here, we have here balanced put, the first is done as
part of fput(filp) -> ib_uverbs_event_close_file ->
kref_put(&file->ref, ib_uverbs_release_event_file) and the second at
the end of this function as part of the err: label
kref_put(&ev_file->ref, ib_uverbs_release_event_file);

Ugh, that is so gross, seriously? Sure, the counts work out, but that
is *totally unreadable*.

Sigh, just use this:

  struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
                                         int is_async)
  {
         struct ib_uverbs_event_file *ev_file;
         struct file *filp;
+       int ret;

-       ev_file = kmalloc(sizeof *ev_file, GFP_KERNEL);
+       ev_file = kzalloc(sizeof(*ev_file), GFP_KERNEL);
         if (!ev_file)
                 return ERR_PTR(-ENOMEM);

@@ -555,15 +561,41 @@ struct file *ib_uverbs_alloc_event_file(struct 
ib_uverbs_file *uverbs_file,
         INIT_LIST_HEAD(&ev_file->event_list);
         init_waitqueue_head(&ev_file->poll_wait);
         ev_file->uverbs_file = uverbs_file;
+       kref_get(&ev_file->uverbs_file->ref);
         ev_file->async_queue = NULL;
-       ev_file->is_async    = is_async;
         ev_file->is_closed   = 0;

         filp = anon_inode_getfile("[infinibandevent]", &uverbs_event_fops,
                                   ev_file, O_RDONLY);
         if (IS_ERR(filp))
-               kfree(ev_file);
+               goto err_put_refs;
+
+       if (is_async) {
+               WARN_ON(uverbs_file->async_file);
+               uverbs_file->async_file = ev_file;
+               kref_get(&uverbs_file->async_file->ref);
+               INIT_IB_EVENT_HANDLER(&uverbs_file->event_handler,
+                                     uverbs_file->device->ib_dev,
+                                     ib_uverbs_event_handler);
+               ret = ib_register_event_handler(&uverbs_file->event_handler);
+               if (ret)
+                       goto err_put_file;
+
+               /* At that point async file stuff was fully set */
+               ev_file->is_async = 1;
+       }
+
+       return filp;
+
+err_put_file:
+       fput(filp);
+       kref_put(&uverbs_file->async_file->ref, ib_uverbs_release_file);

It should be:
kref_put(&uverbs_file->async_file->ref, ib_uverbs_release_event_file)
instead of:
kref_put(&uverbs_file->async_file->ref, ib_uverbs_release_file);

Please note that in that approach we duplicate above line as it appears here and in below err_put_refs label as uverbs_file->async_file is really ev_file.

In my patch we used one line instead of those duplicated lines, however as you think that it clarifies things will go with your suggestion after fixing above note, thanks.


+       uverbs_file->async_file = NULL;
+       return ERR_PTR(ret);

+err_put_refs:
+       kref_put(&ev_file->uverbs_file->ref, ib_uverbs_release_file);
+       kref_put(&ev_file->ref, ib_uverbs_release_event_file);
         return filp;
  }

Jason


--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to