From patchwork Mon Apr 11 13:19:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Finney X-Patchwork-Id: 698091 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3BDKVhU027860 for ; Mon, 11 Apr 2011 13:20:33 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751995Ab1DKNUU (ORCPT ); Mon, 11 Apr 2011 09:20:20 -0400 Received: from seldrel01.sonyericsson.com ([212.209.106.2]:4220 "EHLO seldrel01.sonyericsson.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751988Ab1DKNUT (ORCPT ); Mon, 11 Apr 2011 09:20:19 -0400 From: Sean Finney To: Steve French CC: linux-cifs@vger.kernel.org, Sean Finney Subject: [PATCH v5 5/6] cifs: Use kstrndup for cifs_sb->mountdata Date: Mon, 11 Apr 2011 15:19:34 +0200 Message-ID: <1302527975-16549-5-git-send-email-seanius@seanius.net> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1302527975-16549-1-git-send-email-seanius@seanius.net> References: <1302527975-16549-1-git-send-email-seanius@seanius.net> MIME-Version: 1.0 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 11 Apr 2011 13:20:34 +0000 (UTC) A relatively minor nit, but also clarified the "consensus" from the preceding comments that it is in fact better to try for the kstrdup early and cleanup while cleaning up is still a simple thing to do. Reviewed-By: Steve French Signed-off-by: Sean Finney --- fs/cifs/cifsfs.c | 17 ++++++----------- 1 files changed, 6 insertions(+), 11 deletions(-) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index fb6a2ad..2f646cb 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -134,24 +134,19 @@ cifs_read_super(struct super_block *sb, void *data, cifs_sb->bdi.ra_pages = default_backing_dev_info.ra_pages; #ifdef CONFIG_CIFS_DFS_UPCALL - /* copy mount params to sb for use in submounts */ - /* BB: should we move this after the mount so we - * do not have to do the copy on failed mounts? - * BB: May be it is better to do simple copy before - * complex operation (mount), and in case of fail - * just exit instead of doing mount and attempting - * undo it if this copy fails?*/ + /* + * Copy mount params to sb for use in submounts. Better to do + * the copy here and deal with the error before cleanup gets + * complicated post-mount. + */ if (data) { - int len = strlen(data); - cifs_sb->mountdata = kzalloc(len + 1, GFP_KERNEL); + cifs_sb->mountdata = kstrndup(data, PAGE_SIZE, GFP_KERNEL); if (cifs_sb->mountdata == NULL) { bdi_destroy(&cifs_sb->bdi); kfree(sb->s_fs_info); sb->s_fs_info = NULL; return -ENOMEM; } - strncpy(cifs_sb->mountdata, data, len + 1); - cifs_sb->mountdata[len] = '\0'; } #endif