From patchwork Wed Jul 23 21:47:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: HIMANGI SARAOGI X-Patchwork-Id: 4613341 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C8E39C0514 for ; Wed, 23 Jul 2014 21:47:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DEDAF201BF for ; Wed, 23 Jul 2014 21:47:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0F03A20148 for ; Wed, 23 Jul 2014 21:47:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933780AbaGWVrQ (ORCPT ); Wed, 23 Jul 2014 17:47:16 -0400 Received: from mail-pd0-f172.google.com ([209.85.192.172]:60068 "EHLO mail-pd0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933568AbaGWVrP (ORCPT ); Wed, 23 Jul 2014 17:47:15 -0400 Received: by mail-pd0-f172.google.com with SMTP id ft15so2357653pdb.31 for ; Wed, 23 Jul 2014 14:47:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=EQEJpjzOjkrSWaQXM+lCaBcWlIDqk8K5B+nrc4oEAoo=; b=PEc8nZBX86CPVJOFqoaSDZfvfxh4C4BfhBLineIk+jM8+WeAhYe1ivXNx50sWMDqgw QrgJRAV2WdhUkVTLAaIVkHXkuRq9mZhnILDURCM4E7/pCox5gmPDg0dmsnauuCap8vBQ XpfIln0co3DT1dHY6ac6uO1e2bwDkkrwER4CcQvlVi+5M5kMwyT/xEeL6t7+/a9bFafL px6R8cKi7eURBgUcYmpEkKWe6/POUL8a8oWJaLq4Ws5cpK0ZSutXqqJNPLtB5NGE7jpT Z5UJ5gx3TLdnXx4mo4qCL2vyCb1Qpwap9YHAJ2aXxFq2CvseOxbLzms2TZwfhzSuJ4mo F5rg== X-Received: by 10.66.158.130 with SMTP id wu2mr5401951pab.59.1406152035391; Wed, 23 Jul 2014 14:47:15 -0700 (PDT) Received: from localhost ([125.17.132.98]) by mx.google.com with ESMTPSA id w7sm3385479pbs.74.2014.07.23.14.47.11 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 23 Jul 2014 14:47:14 -0700 (PDT) Date: Thu, 24 Jul 2014 03:17:07 +0530 From: Himangi Saraogi To: Yehuda Sadeh , Sage Weil , Alex Elder , ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Julia Lawall Subject: [PATCH] rbd: Use rbd_segment_name_free Message-ID: <20140723214707.GA8100@himangi-Dell> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Free memory allocated using kmem_cache_zalloc using kmem_cache_free rather than kfree. The helper rbd_segment_name_free does the job here. Its position is shifted above the calling function. The Coccinelle semantic patch that detects this change is as follows: // @@ expression x,E,c; @@ x = \(kmem_cache_alloc\|kmem_cache_zalloc\|kmem_cache_alloc_node\)(c,...) ... when != x = E when != &x ?-kfree(x) +kmem_cache_free(c,x) // Signed-off-by: Himangi Saraogi Acked-by: Julia Lawall --- drivers/block/rbd.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index b2c98c1..1b86b5e 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -1139,6 +1139,13 @@ static void rbd_dev_mapping_clear(struct rbd_device *rbd_dev) rbd_dev->mapping.features = 0; } +static void rbd_segment_name_free(const char *name) +{ + /* The explicit cast here is needed to drop the const qualifier */ + + kmem_cache_free(rbd_segment_name_cache, (void *)name); +} + static const char *rbd_segment_name(struct rbd_device *rbd_dev, u64 offset) { char *name; @@ -1158,20 +1165,13 @@ static const char *rbd_segment_name(struct rbd_device *rbd_dev, u64 offset) if (ret < 0 || ret > CEPH_MAX_OID_NAME_LEN) { pr_err("error formatting segment name for #%llu (%d)\n", segment, ret); - kfree(name); + rbd_segment_name_free(name); name = NULL; } return name; } -static void rbd_segment_name_free(const char *name) -{ - /* The explicit cast here is needed to drop the const qualifier */ - - kmem_cache_free(rbd_segment_name_cache, (void *)name); -} - static u64 rbd_segment_offset(struct rbd_device *rbd_dev, u64 offset) { u64 segment_size = (u64) 1 << rbd_dev->header.obj_order;