From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752500AbbIXIfE (ORCPT ); Thu, 24 Sep 2015 04:35:04 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:49304 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752395AbbIXIe7 (ORCPT ); Thu, 24 Sep 2015 04:34:59 -0400 X-AuditID: cbfec7f4-f79c56d0000012ee-d7-5603b5b14f87 Subject: Re: [PATCH 22/31] fs/ntfs: use kmemdup rather than duplicating its implementation To: Anton Altaparmakov References: <1438934377-4922-1-git-send-email-a.hajda@samsung.com> <1438934377-4922-23-git-send-email-a.hajda@samsung.com> <449F7556-40CD-4BE6-9E5F-0F5603152998@tuxera.com> Cc: Bartlomiej Zolnierkiewicz , Marek Szyprowski , linux-kernel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net From: Andrzej Hajda Message-id: <5603B599.6090803@samsung.com> Date: Thu, 24 Sep 2015 10:34:33 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-version: 1.0 In-reply-to: <449F7556-40CD-4BE6-9E5F-0F5603152998@tuxera.com> Content-type: text/plain; charset=windows-1252 Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrDLMWRmVeSWpSXmKPExsVy+t/xy7obtzKHGaz8oG6xc9MWVouNM9az WlzeNYfNor1jDqPF2iN32R1YPXYv+Mzk0bdlFaPHipXvmTw+b5ILYInisklJzcksSy3St0vg yni8+DF7wUe+iuYHf5kbGDt4uhg5OSQETCRm/jvDBGGLSVy4t56ti5GLQ0hgKaPE76nHmSCc 54wSH5+uAqsSFoiROH/pC0sXIweHiICmxKpfNRA1GxglZt1pZwVxmAXWMkqcW7CMBaSBDajo 7+abbCA2r4CWxMIt09hBbBYBVYlfHQ8ZQWxRgQiJU2ffQtUISvyYfA+sl1PATuLO/1ZmkGXM AnoS9y9qgYSZBeQlNq95yzyBUWAWko5ZCFWzkFQtYGRexSiaWppcUJyUnmuoV5yYW1yal66X nJ+7iRESxl92MC4+ZnWIUYCDUYmH10GLOUyINbGsuDL3EKMEB7OSCK9SP1CINyWxsiq1KD++ qDQntfgQozQHi5I479xd70OEBNITS1KzU1MLUotgskwcnFINjNz/ghZ8WPDNKtra5Vz1u4UX Y38eEfRVdkhPvbwr/oTON+lyfm5PlusyUWXu+6NUjs85YFix4NDa8uL0Oc+vn4+IkpTg+ab5 /FxN0968e1rfMz9IO/bWiHY+Fs6a8+jQx5t399edOPqqfNv2Eoak5om5Jg/n3xTeFpP7cW5E ceuMn7fbpzw301NiKc5INNRiLipOBADiFME9XwIAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/23/2015 12:21 PM, Anton Altaparmakov wrote: > Hi Andrzej, > > Thanks for your patch. It looks fine though I don't quite see the point of it to be honest. > > It actually adds an additional function call (kmemdup() is not inline) just to save 1 line of source code in the driver and I don't think it improves readability or anything so why bother? What does it gain? kmemdup replaces combo (kmalloc + memdup) with one call. The patch follows quite common practice of abstracting out common patterns. Regards Andrzej > > Best regards, > > Anton > >> On 7 Aug 2015, at 08:59, Andrzej Hajda wrote: >> >> The patch was generated using fixed coccinelle semantic patch >> scripts/coccinelle/api/memdup.cocci [1]. >> >> [1]: http://permalink.gmane.org/gmane.linux.kernel/2014320 >> >> Signed-off-by: Andrzej Hajda >> --- >> fs/ntfs/dir.c | 7 +++---- >> 1 file changed, 3 insertions(+), 4 deletions(-) >> >> diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c >> index 9e38daf..2b7fef0 100644 >> --- a/fs/ntfs/dir.c >> +++ b/fs/ntfs/dir.c >> @@ -1172,14 +1172,13 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor) >> * map the mft record without deadlocking. >> */ >> rc = le32_to_cpu(ctx->attr->data.resident.value_length); >> - ir = kmalloc(rc, GFP_NOFS); >> + /* Copy the index root value (it has been verified in read_inode). */ >> + ir = kmemdup((u8 *)ctx->attr + le16_to_cpu(ctx->attr->data.resident.value_offset), >> + rc, GFP_NOFS); >> if (unlikely(!ir)) { >> err = -ENOMEM; >> goto err_out; >> } >> - /* Copy the index root value (it has been verified in read_inode). */ >> - memcpy(ir, (u8*)ctx->attr + >> - le16_to_cpu(ctx->attr->data.resident.value_offset), rc); >> ntfs_attr_put_search_ctx(ctx); >> unmap_mft_record(ndir); >> ctx = NULL; >> -- >> 1.9.1