Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1103254ybi; Wed, 3 Jul 2019 09:32:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqzvXgKwWtDFIz9w2m75wGu3A9NyM0exqGH6LZ1OleNfFQbmFFlDHYMBCn7vX1EJfeOtQ4ru X-Received: by 2002:a17:902:2bc5:: with SMTP id l63mr44788566plb.30.1562171549210; Wed, 03 Jul 2019 09:32:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562171549; cv=none; d=google.com; s=arc-20160816; b=oqE9ZK6TWDbbUFnfzN6og12u61xT5+dWPoWPbpWc5sbmzbPZYvNvZICoLmTiygVquz GdwK6HC0w05iFTHBveTNUalspGdXF/A2i352SRT4vSvgAsdCLcKCqmvAOY3w+HMTsIO1 9J2l/tOMcmvhX8NlACcjlz+0joERrBSuY+fQ74tZ+M35Nl6bf/B+wYaPIaRpB0M4JF95 LjePgw7vJlEdrCpF42xErnxtvdl5s/eye3S7b7iTz1+rty1XViQNrv+NBs3wib13Tvs0 4Xj7tAqD39WWPQGJrmZ3eUxUHkhz9e4ceajx3mmgRYUNS9+VtEglOo63+ozOa9rFqqPD wZdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:message-id:date:subject:cc:from :dkim-signature; bh=BupW8djDuFe89cHMmRkInscHcPGdbc7VTC98zH01S3U=; b=cwtn9wh+ta8KZksLg4gZsSLadWWmTz84Tm2Z+r4A0UmeZSzUVHbPlZtguJBk/Rau7A CN6SL1yZwndS5jHoefAZcrBrH2fOIwkRXQje1mSDwcKne14EhA7DI2tE8taiOa8mFiTc xLByS1v6zNM2EJXJKc34JWdKJCznrtFnLtCxWLaLRh5rBbNL/Mnd4PniUPivIrXpStak szdqAI+6rCVoWHyv703vFisiZ6MdsuM/vYZTBOaoLJOjy6CmsRl6TQC1ahKk6sHPF7QO fJModpiVlWsa6QL0LTJQevEyJS0fsFHSOeqRZYEnOd1XsFSbTK0eLpY9hmU5lblQoZGh B1Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=m8KinkxP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n18si2566625plp.215.2019.07.03.09.32.14; Wed, 03 Jul 2019 09:32:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=m8KinkxP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727264AbfGCQbD (ORCPT + 99 others); Wed, 3 Jul 2019 12:31:03 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:37927 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726989AbfGCQbC (ORCPT ); Wed, 3 Jul 2019 12:31:02 -0400 Received: by mail-pg1-f193.google.com with SMTP id z75so1511749pgz.5; Wed, 03 Jul 2019 09:31:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=BupW8djDuFe89cHMmRkInscHcPGdbc7VTC98zH01S3U=; b=m8KinkxPC+pzBURKLRIVZhFrk0msuXXzw46KVzKl5hT0vtQMAmO0XE7gYTVNKhX0KB 0rTP9eTaAjOch9pVE4RThGvROv1kVUXG0QDbI7CUu+QtcZH1FdEgteMmSSP1/8ey5Tqn dvsZJwDaj37WZsth4bdzMBEAC8i43AMxFyEO/3EofBlAF4HszFuKsyzoKuRa7wlRqY3m nmocrMiDgGKNh7pUi8vpMkXAdY8bl2ILWycSQz505Su9S+ToXAds+WatABepWWRSR29v CgtvwRApZDl4lIgytR/0upLZO7/eGMWzd49R6T/oqVzBIZXykLCsaf7sgyNc8wxxFzrE 0wvA== 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; bh=BupW8djDuFe89cHMmRkInscHcPGdbc7VTC98zH01S3U=; b=UczH6oqw8yx388sKRNNRS0ZozvwmPfBrc+FohG6Y6u4kg2YIR7JzMsywWzdeYGMT37 Mg85p5xDtaocsl8m3mkaVGS5/6KJzSixS+HUX6dvDwg9t2r3fEHndvvMIMPziX9FHUfg 19PYG0voiARmC2wVJUeVNxGcCAM+apZL5iYhQz2PGqc2QsVCdmvSX0KGgZP32iTlEkrA E5p3GaKptJVrtqaiNk3msp9t+4xCvafbXxOrB0EoRJfPKJg2fODJbHP7+voTnQnaNai0 tR9sk9zbySShgwxn53hjsbqHlvKJmGN3XDGG1aMDpoSsugG3F4rZwIaH+xb+yP+zETZ5 DZWg== X-Gm-Message-State: APjAAAUZWFDiFocCppB87k2C1uuV9GfhB0uCFs1LU9XyipfiyC6J/Eqw rfDfsP2S42Y5/WWLwsWjc7/Hy+BvmUI= X-Received: by 2002:a63:fa0d:: with SMTP id y13mr37846873pgh.258.1562171462276; Wed, 03 Jul 2019 09:31:02 -0700 (PDT) Received: from hfq-skylake.ipads-lab.se.sjtu.edu.cn ([202.120.40.82]) by smtp.googlemail.com with ESMTPSA id 137sm6206838pfz.112.2019.07.03.09.30.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2019 09:31:01 -0700 (PDT) From: Fuqian Huang Cc: Steve French , linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-kernel@vger.kernel.org, Fuqian Huang Subject: [PATCH v2 26/35] cifs: Use kmemdup rather than duplicating its implementation Date: Thu, 4 Jul 2019 00:30:50 +0800 Message-Id: <20190703163050.577-1-huangfq.daxian@gmail.com> X-Mailer: git-send-email 2.11.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org kmemdup is introduced to duplicate a region of memory in a neat way. Rather than kmalloc/kzalloc + memcpy, which the programmer needs to write the size twice (sometimes lead to mistakes), kmemdup improves readability, leads to smaller code and also reduce the chances of mistakes. Suggestion to use kmemdup rather than using kmalloc/kzalloc + memcpy. Signed-off-by: Fuqian Huang --- Changes in v2: - Fix a typo in commit message (memset -> memcpy) fs/cifs/smb2pdu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 75311a8a68bf..ab8dc73d2282 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -2550,12 +2550,11 @@ SMB2_ioctl_init(struct cifs_tcon *tcon, struct smb_rqst *rqst, * indatalen is usually small at a couple of bytes max, so * just allocate through generic pool */ - in_data_buf = kmalloc(indatalen, GFP_NOFS); + in_data_buf = kmemdup(in_data, indatalen, GFP_NOFS); if (!in_data_buf) { cifs_small_buf_release(req); return -ENOMEM; } - memcpy(in_data_buf, in_data, indatalen); } req->CtlCode = cpu_to_le32(opcode); -- 2.11.0