diff mbox

ceph: fix invalid point dereference for error case in mdsc destroy

Message ID 1521006453-10319-1-git-send-email-cgxu519@gmx.com (mailing list archive)
State New, archived
Headers show

Commit Message

Chengguang Xu March 14, 2018, 5:47 a.m. UTC
1. set fsc->mdsc after successfully allocate all necessary memory
in mdsc init.
2. if fsc->mdsc is NULL, just skip destroy operation in mdsc destroy.

Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
---
 fs/ceph/mds_client.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Yan, Zheng March 14, 2018, 8:22 a.m. UTC | #1
On Wed, Mar 14, 2018 at 1:47 PM, Chengguang Xu <cgxu519@gmx.com> wrote:
> 1. set fsc->mdsc after successfully allocate all necessary memory
> in mdsc init.
> 2. if fsc->mdsc is NULL, just skip destroy operation in mdsc destroy.
>
> Signed-off-by: Chengguang Xu <cgxu519@gmx.com>
> ---
>  fs/ceph/mds_client.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
> index e932c06..97dcc04 100644
> --- a/fs/ceph/mds_client.c
> +++ b/fs/ceph/mds_client.c
> @@ -3598,7 +3598,6 @@ int ceph_mdsc_init(struct ceph_fs_client *fsc)
>         if (!mdsc)
>                 return -ENOMEM;
>         mdsc->fsc = fsc;
> -       fsc->mdsc = mdsc;
>         mutex_init(&mdsc->mutex);
>         mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS);
>         if (!mdsc->mdsmap) {
> @@ -3606,6 +3605,7 @@ int ceph_mdsc_init(struct ceph_fs_client *fsc)
>                 return -ENOMEM;
>         }
>
> +       fsc->mdsc = mdsc;
>         init_completion(&mdsc->safe_umount_waiters);
>         init_waitqueue_head(&mdsc->session_close_wq);
>         INIT_LIST_HEAD(&mdsc->waiting_for_map);
> @@ -3891,6 +3891,9 @@ void ceph_mdsc_destroy(struct ceph_fs_client *fsc)
>         struct ceph_mds_client *mdsc = fsc->mdsc;
>         dout("mdsc_destroy %p\n", mdsc);
>
> +       if (!mdsc)
> +               return;
> +
>         /* flush out any connection work with references to us */
>         ceph_msgr_flush();
>
> --
> 1.8.3.1
>

Applied, thanks

Yan, Zheng

> --
> To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index e932c06..97dcc04 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -3598,7 +3598,6 @@  int ceph_mdsc_init(struct ceph_fs_client *fsc)
 	if (!mdsc)
 		return -ENOMEM;
 	mdsc->fsc = fsc;
-	fsc->mdsc = mdsc;
 	mutex_init(&mdsc->mutex);
 	mdsc->mdsmap = kzalloc(sizeof(*mdsc->mdsmap), GFP_NOFS);
 	if (!mdsc->mdsmap) {
@@ -3606,6 +3605,7 @@  int ceph_mdsc_init(struct ceph_fs_client *fsc)
 		return -ENOMEM;
 	}
 
+	fsc->mdsc = mdsc;
 	init_completion(&mdsc->safe_umount_waiters);
 	init_waitqueue_head(&mdsc->session_close_wq);
 	INIT_LIST_HEAD(&mdsc->waiting_for_map);
@@ -3891,6 +3891,9 @@  void ceph_mdsc_destroy(struct ceph_fs_client *fsc)
 	struct ceph_mds_client *mdsc = fsc->mdsc;
 	dout("mdsc_destroy %p\n", mdsc);
 
+	if (!mdsc)
+		return;
+
 	/* flush out any connection work with references to us */
 	ceph_msgr_flush();