Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp761159pxa; Thu, 27 Aug 2020 15:19:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVSSMziJkH1iiw06o70Y5efs0IcdrLQH0I9FjE/9JNPNZpB/Qv1+55/4r6CZshNSUgl51b X-Received: by 2002:a50:ec89:: with SMTP id e9mr14003309edr.32.1598566740478; Thu, 27 Aug 2020 15:19:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598566740; cv=none; d=google.com; s=arc-20160816; b=SQNCpW2nSNvam535EVKLm0m3OZfbrDsgB9VRZ/DYvxa1wiNgFvWTXd4J2t2fzGRTXT ukIGjIBcJV2yFEiZxJybiJQ3mRKxPVvOC3keQZiy58wRWz3pMUnYZfkk+zVs8Oz0zM7F zwaG75IO/f7Egu09MeSvJ5wzEYlyRmWMUAjPqy98XBJt9fUyU9gh5Xbr0P/V2Q/IVZf6 nCiFIa1PIl22vM4D8iJ+rJTWPsRwRgPN0E70lNVMt0y1VRwvV0924TmriKHWwFVeNGhZ aGSHlWwjvLR9bx71QjflcAfgbS7RQdFKPvDySJRiJGBrlAl7SP7+D5B+PWpI3x85RFj9 tVPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=O0B+Xa7wBPjWNJbvCt+g8d/rKr338hhSqU8XtS/hi/8=; b=pu/l5si9Oars+gDqcC8jlb1tckdy4HFzXU7uk0nCmOBL6iE0AsEHevWSqgXABGZTYG hn6iILFlF5k9FuCPd9FBVOEr1a3+l8k20S+Yr2DB26tj1Fe05hiJ+Co83gNYEqqqVA30 IbvHY/MNY5M0G9fY7AfIQ4uAVloLu3yKj5MaIiD4E73+34aLg8sB8apVbBGjt9k9TiEa Y3j+wsIYFN55e9ey/WSQl9YUhx2LEqJeBPBAHgRXGFOOWoYFh01IyxijN2Z5PGjNfc5N x8Oi58NyYkLNNAWBzK3rEcQcr+/mButD07+KEveUijjewh5vg9untYM282IEH24ItPMx bYHg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t27si2286367ejf.672.2020.08.27.15.18.37; Thu, 27 Aug 2020 15:19:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727937AbgH0WRN (ORCPT + 99 others); Thu, 27 Aug 2020 18:17:13 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:46522 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726266AbgH0WRM (ORCPT ); Thu, 27 Aug 2020 18:17:12 -0400 Received: by mail-lj1-f193.google.com with SMTP id h19so8196597ljg.13 for ; Thu, 27 Aug 2020 15:17:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O0B+Xa7wBPjWNJbvCt+g8d/rKr338hhSqU8XtS/hi/8=; b=jZJK+wpyjB3E9qLiRlMS6AiaH7lzcsi5MKgYpKCyUNoCeV/WNrNvc3cHkjAKjUi2XP pBjCwL5k8jlpFqM+iabVQC0zxSkV6F5Z19S7QJdNJ/aPyTFaV/NdgWYX21T73qQnvRfX 9SNx5APE5TGJdFklCOPkG7gfFoC6qarxkln+K9bKMoqX9QWQx4MydQ1U2LC++jfv7lDk DxKBaVD79lWpjkJ+4AKIFBJ5oYkS7GXuXWmCq8aZ8qnz+0zshx0p4ITg6P16C0q4k5Fu c6EpxJli4h2QCrXgJzzxtkKRFDjEK49oUVY50XSSHejB6tK7OrYKAyEdQEss9ejzXZQv BBpQ== X-Gm-Message-State: AOAM533X9XBhfPnH7UQ01ZFQwW+Nf9AQyRWsU74Faq+tY1X1gyqbKGD6 nfHSblH46tecxRsgY5WgL3MLN2xWgcs= X-Received: by 2002:a2e:85d3:: with SMTP id h19mr11410061ljj.363.1598566630142; Thu, 27 Aug 2020 15:17:10 -0700 (PDT) Received: from localhost.localdomain ([213.87.147.111]) by smtp.googlemail.com with ESMTPSA id r18sm738387ljm.34.2020.08.27.15.17.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Aug 2020 15:17:09 -0700 (PDT) From: Denis Efremov To: Jan Kara Cc: Denis Efremov , linux-kernel@vger.kernel.org, Joe Perches , "Gustavo A . R . Silva" Subject: [PATCH v3] udf: Use kvzalloc() in udf_sb_alloc_bitmap() Date: Fri, 28 Aug 2020 01:16:52 +0300 Message-Id: <20200827221652.64660-1-efremov@linux.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200827151923.40067-1-efremov@linux.com> References: <20200827151923.40067-1-efremov@linux.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use kvzalloc() in udf_sb_alloc_bitmap() instead of open-coding it. Size computation wrapped in struct_size() macro to prevent potential integer overflows. Signed-off-by: Denis Efremov --- Changes in v2: - size computation wrapped in struct_size() Changes in v3: - int size dropped fs/udf/super.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/fs/udf/super.c b/fs/udf/super.c index 1c42f544096d..d9eabbe368ff 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c @@ -1006,18 +1006,10 @@ int udf_compute_nr_groups(struct super_block *sb, u32 partition) static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index) { struct udf_bitmap *bitmap; - int nr_groups; - int size; - - nr_groups = udf_compute_nr_groups(sb, index); - size = sizeof(struct udf_bitmap) + - (sizeof(struct buffer_head *) * nr_groups); - - if (size <= PAGE_SIZE) - bitmap = kzalloc(size, GFP_KERNEL); - else - bitmap = vzalloc(size); /* TODO: get rid of vzalloc */ + int nr_groups = udf_compute_nr_groups(sb, index); + bitmap = kvzalloc(struct_size(bitmap, s_block_bitmap, nr_groups), + GFP_KERNEL); if (!bitmap) return NULL; -- 2.26.2