ceph: fix null pointer dereference in discard_cap_releases()
authorYan, Zheng <zheng.z.yan@intel.com>
Mon, 24 Mar 2014 01:56:43 +0000 (09:56 +0800)
committerSage Weil <sage@inktank.com>
Sat, 5 Apr 2014 04:07:17 +0000 (21:07 -0700)
send_mds_reconnect() may call discard_cap_releases() after all
release messages have been dropped by cleanup_cap_releases()

Signed-off-by: Yan, Zheng <zheng.z.yan@intel.com>
Reviewed-by: Sage Weil <sage@inktank.com>
fs/ceph/mds_client.c

index f260bd8d61cdf7fb7bd59f2d4a4eb42562bd1fb9..77640ada487ae20d84facf3ed39402d9c6398f21 100644 (file)
@@ -1462,15 +1462,18 @@ static void discard_cap_releases(struct ceph_mds_client *mdsc,
 
        dout("discard_cap_releases mds%d\n", session->s_mds);
 
-       /* zero out the in-progress message */
-       msg = list_first_entry(&session->s_cap_releases,
-                              struct ceph_msg, list_head);
-       head = msg->front.iov_base;
-       num = le32_to_cpu(head->num);
-       dout("discard_cap_releases mds%d %p %u\n", session->s_mds, msg, num);
-       head->num = cpu_to_le32(0);
-       msg->front.iov_len = sizeof(*head);
-       session->s_num_cap_releases += num;
+       if (!list_empty(&session->s_cap_releases)) {
+               /* zero out the in-progress message */
+               msg = list_first_entry(&session->s_cap_releases,
+                                       struct ceph_msg, list_head);
+               head = msg->front.iov_base;
+               num = le32_to_cpu(head->num);
+               dout("discard_cap_releases mds%d %p %u\n",
+                    session->s_mds, msg, num);
+               head->num = cpu_to_le32(0);
+               msg->front.iov_len = sizeof(*head);
+               session->s_num_cap_releases += num;
+       }
 
        /* requeue completed messages */
        while (!list_empty(&session->s_cap_releases_done)) {