From patchwork Fri Aug 24 16:32:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1372121 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 3BCB6DF28C for ; Fri, 24 Aug 2012 16:32:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759865Ab2HXQco (ORCPT ); Fri, 24 Aug 2012 12:32:44 -0400 Received: from mail-ob0-f174.google.com ([209.85.214.174]:58290 "EHLO mail-ob0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759622Ab2HXQcn (ORCPT ); Fri, 24 Aug 2012 12:32:43 -0400 Received: by mail-ob0-f174.google.com with SMTP id uo13so4590607obb.19 for ; Fri, 24 Aug 2012 09:32:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=PLt7IaXJzOyOxSOVVuyKMXjAAGVVy+mhO9J3+Z1I9Nc=; b=XZgUFJZuG9yBsUAggNegP8x8eeJBBth8C4UIl5B8/mhJ4AXN4vjeefE/1JArO2ROSi D3fyiunJk3VIopddTTQWKn5YNwJrYHQJ4cPE2FExk96mGRJLYLgBjCwBXTC20Qenf9co BFb6ulYZBJpFWPsFIg0x/uwbEG6pOG2blBy4ysZPRl/wHS9tp1F3UyJ2s4ZRps4lepTV wo7RXU347yStSS5wk8R32WWD6CeMZNCqXcGhvSGJ7IfjcjNeDPT3b13MIcYV4VqeAQLI +bKDjcM9Wt4c0Cl+iErV43ZPCm9/CWVl5uQT55RqVIU4GCfJMYxX38v08wiSgBi0UDJu 3j+g== Received: by 10.50.207.73 with SMTP id lu9mr2876856igc.19.1345825962710; Fri, 24 Aug 2012 09:32:42 -0700 (PDT) Received: from [172.22.22.4] (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPS id gh2sm671426igb.9.2012.08.24.09.32.37 (version=SSLv3 cipher=OTHER); Fri, 24 Aug 2012 09:32:41 -0700 (PDT) Message-ID: <5037ACA5.5060203@inktank.com> Date: Fri, 24 Aug 2012 11:32:37 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 02/11] rbd: don't over-allocate space for object prefix References: <5037AB20.4000103@inktank.com> In-Reply-To: <5037AB20.4000103@inktank.com> X-Gm-Message-State: ALoCoQkVh3WETRrLNStykFpdcYZ+zU+bIq5flet4IaDZhKTnZv2tgbQtMcNGCAoxkAIPaeZ1B9dv Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org In rbd_header_from_disk() the object prefix buffer is sized based on the maximum size it's block_name equivalent on disk could be. Instead, only allocate enough to hold NUL-terminated string from the on-disk header--or the maximum size of no NUL is found. Signed-off-by: Alex Elder Reviewed-by: Yehuda Sadeh --- drivers/block/rbd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) header->snap_names_len = le64_to_cpu(ondisk->snap_names_len); diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 81b5344..a8a4cba 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -519,18 +519,19 @@ static int rbd_header_from_disk(struct rbd_image_header *header, struct rbd_image_header_ondisk *ondisk) { u32 snap_count; + size_t len; size_t size; memset(header, 0, sizeof (*header)); snap_count = le32_to_cpu(ondisk->snap_count); - size = sizeof (ondisk->block_name) + 1; - header->object_prefix = kmalloc(size, GFP_KERNEL); + len = strnlen(ondisk->block_name, sizeof (ondisk->block_name)); + header->object_prefix = kmalloc(len + 1, GFP_KERNEL); if (!header->object_prefix) return -ENOMEM; - memcpy(header->object_prefix, ondisk->block_name, size - 1); - header->object_prefix[size - 1] = '\0'; + memcpy(header->object_prefix, ondisk->block_name, len); + header->object_prefix[len] = '\0'; if (snap_count) {