Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1178848iog; Tue, 14 Jun 2022 00:19:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uyVLTX0XUvXzD43i1yJg/4foxAW88Y8UZ4ta4yAznrW5VC4q4hzToWMRLxKydbC3auXf4V X-Received: by 2002:aa7:c9c9:0:b0:431:962f:f61e with SMTP id i9-20020aa7c9c9000000b00431962ff61emr4201115edt.189.1655191193142; Tue, 14 Jun 2022 00:19:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655191193; cv=none; d=google.com; s=arc-20160816; b=uBKk1rzXo3JVZ7RP+686isqoI8Fmmyd/VyGdrqrb7tIGW7uy53SjOEkXCzcbNHd/hW YnuGXCEBYYlhwmaGjF5Hj22wm9WGid3mOl2/AHgrotF7YikPLQ7x0dXOTv0xccOAPnc0 DmPh5hyr7tIcQdwZr6PPhvoL7sO53LKcyHeGJkwtAzkZEQWx8zXcqXsKOs9tcjSQI0Q0 K3kIbdyUMdHlOVsr4+8rxjz2GcRsMVq8l4+ObabmL3lslRFj/tYGM/VyCpIz0glHiaqX IGNaesYhA7dKpimxDYUXdUeVuxC+TWXGkXtMevgOseCGisXnt8OoOR/1KWOnzx4RlDvC cw8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=X6J0BKlW4G4IsCL+3iZ9aBImBpOPgOfJL08s0F1QS3Y=; b=m2YeyeLBALEnR/XyqRtogSJPMuYcaOJcYdHjgm7xMFFsz3wEvb7n1SvldghYR7+MNE V4733ox+vy1gj1eEBiTbbmaimo2pmLGlRlM3VenRiQ4z0116XbQVBQNZugq/gd4yRPGg gfxJATt6CjOax17X7TnuVxoVot9p6MMECB/eDSGnQK6y9xwEtM+uqSlutaXlJSIg+Jic s+T4782ymMHDq2aN4fNTdhtHLuAnS/+veHShyaIqu6OuvkHffrYVMxJBhdQdynoMGAWG JeMXTndE9TUANbsClw7rsBrnfR8a0rVH+Kj7+bFxbOARbTCzyAUpD0yTGXrrJtYJUJM3 bMJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 4-20020a170906024400b007157046560csi8246735ejl.884.2022.06.14.00.19.27; Tue, 14 Jun 2022 00:19:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353335AbiFNHMK (ORCPT + 99 others); Tue, 14 Jun 2022 03:12:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352657AbiFNHMI (ORCPT ); Tue, 14 Jun 2022 03:12:08 -0400 Received: from mail.nfschina.com (unknown [IPv6:2400:dd01:100f:2:72e2:84ff:fe10:5f45]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7AC983B54C; Tue, 14 Jun 2022 00:12:07 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 71A761E80D5E; Tue, 14 Jun 2022 15:10:47 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ro-17gUlV4U2; Tue, 14 Jun 2022 15:10:44 +0800 (CST) Received: from localhost.localdomain (unknown [180.167.10.98]) (Authenticated sender: liqiong@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 30F761E80D0E; Tue, 14 Jun 2022 15:10:44 +0800 (CST) From: Li Qiong To: Ilya Dryomov , Xiubo Li , Jeff Layton , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, yuzhe@nfschina.com, renyu@nfschina.com, Li Qiong Subject: [PATCH] libceph: check pointer before assigned to "c->rules[]" Date: Tue, 14 Jun 2022 15:10:59 +0800 Message-Id: <20220614071059.23696-1-liqiong@nfschina.com> X-Mailer: git-send-email 2.11.0 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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-kernel@vger.kernel.org It should be better to check pointer firstly, then assign it to c->rules[]. Refine code a little bit. Signed-off-by: Li Qiong --- net/ceph/osdmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c index 2823bb3cff55..6ec5007f96dc 100644 --- a/net/ceph/osdmap.c +++ b/net/ceph/osdmap.c @@ -571,9 +571,9 @@ static struct crush_map *crush_decode(void *pbyval, void *end) goto bad; #endif r = kmalloc(struct_size(r, steps, yes), GFP_NOFS); - c->rules[i] = r; if (r == NULL) goto badmem; + c->rules[i] = r; dout(" rule %d is at %p\n", i, r); r->len = yes; ceph_decode_copy_safe(p, end, &r->mask, 4, bad); /* 4 u8's */ -- 2.11.0