Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1873485rwb; Fri, 11 Nov 2022 01:27:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf7daSMcIAyilN+2F8blqOO+sxp711G+3y/ZpBMp+2h8XhLTcCq2//qhH54oLRXOhLut1b+T X-Received: by 2002:aa7:ccc2:0:b0:461:bff7:9783 with SMTP id y2-20020aa7ccc2000000b00461bff79783mr725816edt.200.1668158841015; Fri, 11 Nov 2022 01:27:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668158841; cv=none; d=google.com; s=arc-20160816; b=DgltPhfqUBExeDGU3NymCFgbbbs8AeHX8ORr9Jv6v/dlEaFdUoUiNdz91gyJxSIuZj zovVQPmDmFjoH/5Z+hV+RBQi09vP6L7xa2n+DQZwZfPP50VzmOFicr6wQWbfQ/qSMHzb 8bgUDltlDokPGBKkIp3CDct2EhC9aT/eNJKhqycrZokRN4ofRtMeb9n/4MP7GlDAcBFU 7SdQoK4QIjqwn2ilV0D3iNGuYBwJwUR1ihnWZOv6Z5XqmRpUsHNE5OL1a1mfX3BOP11y clE/oBRgZ1XtFpOeP55hrnzMSBNGZTRZRNyHDRpDwf34fz9bC6wP22sRWcpQgOjZHtys utMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=ccli40esBiQZSggt3QWfOlkYqLEdXdeEvKYhEu/+ccs=; b=Ru1/PfRDWeB2qYNFVfFunwd98XYlH19TTCXyP7OCUEUMv/9EVUkNLG1yb8Rw6g8uCp eY4ADtENkZ76E2TmaAGE763G6f7YYrynlY5H6sDQdZj8jlUhC7AcP60G+TJlvzcvqouZ YPo4xZEn0JCMKjQmrJT+73KU2l05F9hqEz4RjLF0EkcUZnzaLnBPKKpwq6d8PI1HMpkg rI20kTuUlmF0qpfG/55CKqSyuAQnR36DLPRrPbeoVP9ambvY5rO6IvAHGcbX8O7lq0jF Wi9V0EjkMo2tfKXIDcZ+GykAy5qU/B7wTrDej3usnoBatPfg71Jd+VoH6JJv2rpZm5Tv sNXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go14-20020a1709070d8e00b0078333d9f17bsi1858834ejc.819.2022.11.11.01.26.44; Fri, 11 Nov 2022 01:27:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233163AbiKKJVt (ORCPT + 99 others); Fri, 11 Nov 2022 04:21:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232749AbiKKJVs (ORCPT ); Fri, 11 Nov 2022 04:21:48 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A56E26576; Fri, 11 Nov 2022 01:21:47 -0800 (PST) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N7tVl1F8DzHvnM; Fri, 11 Nov 2022 17:21:19 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.174.58) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 11 Nov 2022 17:21:45 +0800 From: Xiu Jianfeng To: , CC: , Subject: [PATCH -next] NFSD: Use struct_size() helpler in alloc_session() Date: Fri, 11 Nov 2022 17:18:35 +0800 Message-ID: <20221111091835.151942-1-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.174.58] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500023.china.huawei.com (7.185.36.114) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Use struct_size() helper to simplify the code, no functional changes. Signed-off-by: Xiu Jianfeng --- fs/nfsd/nfs4state.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 2ec981fd2985..97badca3135e 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1833,13 +1833,12 @@ static struct nfsd4_session *alloc_session(struct nfsd4_channel_attrs *fattrs, int numslots = fattrs->maxreqs; int slotsize = slot_bytes(fattrs); struct nfsd4_session *new; - int mem, i; + int i; - BUILD_BUG_ON(NFSD_MAX_SLOTS_PER_SESSION * sizeof(struct nfsd4_slot *) - + sizeof(struct nfsd4_session) > PAGE_SIZE); - mem = numslots * sizeof(struct nfsd4_slot *); + BUILD_BUG_ON(struct_size(new, se_slots, NFSD_MAX_SLOTS_PER_SESSION) + > PAGE_SIZE); - new = kzalloc(sizeof(*new) + mem, GFP_KERNEL); + new = kzalloc(struct_size(new, se_slots, numslots), GFP_KERNEL); if (!new) return NULL; /* allocate each struct nfsd4_slot and data cache in one piece */ -- 2.17.1