From patchwork Mon Sep 19 17:03:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 9339925 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 115FA607D0 for ; Mon, 19 Sep 2016 17:04:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F21E6295C9 for ; Mon, 19 Sep 2016 17:04:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E6B9B295DF; Mon, 19 Sep 2016 17:04:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3F7A295C9 for ; Mon, 19 Sep 2016 17:04:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752511AbcISRDv (ORCPT ); Mon, 19 Sep 2016 13:03:51 -0400 Received: from mail-yw0-f194.google.com ([209.85.161.194]:34464 "EHLO mail-yw0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752499AbcISRDu (ORCPT ); Mon, 19 Sep 2016 13:03:50 -0400 Received: by mail-yw0-f194.google.com with SMTP id t67so8397732ywg.1 for ; Mon, 19 Sep 2016 10:03:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FW07o1HbCIJEwlaJi6KhEOrGN2dEdquKAUsFmGbD7JY=; b=WuUmSfuWCjntYrzC9/RQfPxWidvmZ6n4NNCHgAQcDR9X+cmtDjhK0wGyCh6tFwiWkr vmhSXgqLv2H7dLJQR+37ph4oIifYHKPfjBuMNTehvdTxgTmGIRG0xNf6Axf6uJZPp9Y9 invD3rLp9MPbzWKdy7WmsfGJoRNNsUEmLK6+L/U+mqSwLcTmllcUUKm3sH+YfzGPDRdS HHXYIDxkiQUvGD8G9rbjBQGNEB5lL+bJigOo4GF7FsRhcwSiWWCQhXLo3vZ1YpMB0gou KHYNMx3jO66J27kJW0D4FU0YL8eBXxTwg2QN9zmZuO4XEdY38jOeNgM49lZLoyTORnWD A6Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FW07o1HbCIJEwlaJi6KhEOrGN2dEdquKAUsFmGbD7JY=; b=lsoJBafeNTiSF4r6m+VARiRNwCPdsIeslHXrre9b7xtkOWTYKM2iXTfHgEiqKSwZY2 yyqrKg7ge0h1GR2Es3LFp5g0OdYQW9Ty9y1rqdMBmnwL/bB3FKeR2X7VEfmZ/P259U9Q jMCbb30JIhqrWaKpG8e4+zyIFTHtkoJpQLliVYQ1qyppThpnRUQLld8MfQM3mrkvgv4g pWAtif1/ey/WbaVavz6GwVBw3wt64zd6rzr3gRscivl4I7MYDxKit3NUUlxMqBOYqXpE fhVgY+d9lWfkf91EOt9QtK+2/2VpGIwGS8v2JCI32mBh9zdU25aH2p9ssSwaFCo5Cgae Fbvg== X-Gm-Message-State: AE9vXwPYW1+a3NY8ZEXRSt4iCAJWWsB+l//BHC0ArDtc9OHvCxJZnI3bnMwG+ZkkYhF5Cw== X-Received: by 10.13.203.81 with SMTP id n78mr19753813ywd.350.1474304629624; Mon, 19 Sep 2016 10:03:49 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id o14sm9773905ywd.3.2016.09.19.10.03.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Sep 2016 10:03:49 -0700 (PDT) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Cc: Alex Elder Subject: [PATCH 6/8] rbd: rework rbd_img_obj_exists_submit() error paths Date: Mon, 19 Sep 2016 19:03:26 +0200 Message-Id: <1474304608-17958-7-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1474304608-17958-1-git-send-email-idryomov@gmail.com> References: <1474304608-17958-1-git-send-email-idryomov@gmail.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP - don't put obj_request if rbd_obj_request_create() fails - don't leak stat_request if rbd_osd_req_create() fails Reported-by: David Disseldorp Signed-off-by: Ilya Dryomov Reviewed-by: Alex Elder Reviewed-by: David Disseldorp --- drivers/block/rbd.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index b9a4e79a663f..03f171067e08 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -2886,11 +2886,23 @@ static int rbd_img_obj_exists_submit(struct rbd_obj_request *obj_request) { struct rbd_device *rbd_dev = obj_request->img_request->rbd_dev; struct rbd_obj_request *stat_request; - struct page **pages = NULL; + struct page **pages; u32 page_count; size_t size; int ret; + stat_request = rbd_obj_request_create(obj_request->object_name, 0, 0, + OBJ_REQUEST_PAGES); + if (!stat_request) + return -ENOMEM; + + stat_request->osd_req = rbd_osd_req_create(rbd_dev, OBJ_OP_READ, 1, + stat_request); + if (!stat_request->osd_req) { + ret = -ENOMEM; + goto fail_stat_request; + } + /* * The response data for a STAT call consists of: * le64 length; @@ -2902,38 +2914,28 @@ static int rbd_img_obj_exists_submit(struct rbd_obj_request *obj_request) size = sizeof (__le64) + sizeof (__le32) + sizeof (__le32); page_count = (u32)calc_pages_for(0, size); pages = ceph_alloc_page_vector(page_count, GFP_KERNEL); - if (IS_ERR(pages)) - return PTR_ERR(pages); + if (IS_ERR(pages)) { + ret = PTR_ERR(pages); + goto fail_stat_request; + } - ret = -ENOMEM; - stat_request = rbd_obj_request_create(obj_request->object_name, 0, 0, - OBJ_REQUEST_PAGES); - if (!stat_request) - goto out; + osd_req_op_init(stat_request->osd_req, 0, CEPH_OSD_OP_STAT, 0); + osd_req_op_raw_data_in_pages(stat_request->osd_req, 0, pages, size, 0, + false, false); rbd_obj_request_get(obj_request); stat_request->obj_request = obj_request; stat_request->pages = pages; stat_request->page_count = page_count; - - stat_request->osd_req = rbd_osd_req_create(rbd_dev, OBJ_OP_READ, 1, - stat_request); - if (!stat_request->osd_req) - goto out; stat_request->callback = rbd_img_obj_exists_callback; - osd_req_op_init(stat_request->osd_req, 0, CEPH_OSD_OP_STAT, 0); - osd_req_op_raw_data_in_pages(stat_request->osd_req, 0, pages, size, 0, - false, false); rbd_osd_req_format_read(stat_request); rbd_obj_request_submit(stat_request); return 0; -out: - if (ret) - rbd_obj_request_put(obj_request); - +fail_stat_request: + rbd_obj_request_put(stat_request); return ret; }