From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A070C433FE for ; Mon, 14 Feb 2022 09:34:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243768AbiBNJeh (ORCPT ); Mon, 14 Feb 2022 04:34:37 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243979AbiBNJeB (ORCPT ); Mon, 14 Feb 2022 04:34:01 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF206657B8; Mon, 14 Feb 2022 01:32:20 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 789F3B80DCC; Mon, 14 Feb 2022 09:32:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F19CC340E9; Mon, 14 Feb 2022 09:32:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644831138; bh=Q0rgJ3uuJVNFnx5+PCV403tRiCwPGUedbmAIe320ilg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dWm6Y/1Lxy9wICon+bOal6jcnukzUcgu5hpFyiQ/5Khwx8O/IFnMjQEEyjWhk+DMq N3gGnSa0dCon7XRjCK50FbzFx7A/3sob9HXhYOpJoSR2rGEJ59ZC3AFmJ3M/lNaaB5 L7XXID8IedjPYMBA5iiCmQXa9uvKjlaGKy2QmZUU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaoke Wang , Anna Schumaker , Sasha Levin Subject: [PATCH 4.19 10/49] nfs: nfs4clinet: check the return value of kstrdup() Date: Mon, 14 Feb 2022 10:25:36 +0100 Message-Id: <20220214092448.641593412@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214092448.285381753@linuxfoundation.org> References: <20220214092448.285381753@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiaoke Wang [ Upstream commit fbd2057e5329d3502a27491190237b6be52a1cb6 ] kstrdup() returns NULL when some internal memory errors happen, it is better to check the return value of it so to catch the memory error in time. Signed-off-by: Xiaoke Wang Signed-off-by: Anna Schumaker Signed-off-by: Sasha Levin --- fs/nfs/nfs4client.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c index 43659326b5191..c97ec2fa0bbcd 100644 --- a/fs/nfs/nfs4client.c +++ b/fs/nfs/nfs4client.c @@ -1273,8 +1273,11 @@ int nfs4_update_server(struct nfs_server *server, const char *hostname, } nfs_put_client(clp); - if (server->nfs_client->cl_hostname == NULL) + if (server->nfs_client->cl_hostname == NULL) { server->nfs_client->cl_hostname = kstrdup(hostname, GFP_KERNEL); + if (server->nfs_client->cl_hostname == NULL) + return -ENOMEM; + } nfs_server_insert_lists(server); return nfs_probe_destination(server); -- 2.34.1