From patchwork Wed Apr 6 14:26:44 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Finney X-Patchwork-Id: 689951 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 p36ERAwj015203 for ; Wed, 6 Apr 2011 14:27:11 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755975Ab1DFO1L (ORCPT ); Wed, 6 Apr 2011 10:27:11 -0400 Received: from seldrel01.sonyericsson.com ([212.209.106.2]:13032 "EHLO seldrel01.sonyericsson.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756121Ab1DFO1J (ORCPT ); Wed, 6 Apr 2011 10:27:09 -0400 From: Sean Finney To: linux-cifs@vger.kernel.org CC: Sean Finney Subject: [PATCH v4 5/6] cifs: Use kstrndup for cifs_sb->mountdata Date: Wed, 6 Apr 2011 16:26:44 +0200 Message-ID: <1302100005-1848-5-git-send-email-seanius@seanius.net> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1302100005-1848-1-git-send-email-seanius@seanius.net> References: <1302100005-1848-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]); Wed, 06 Apr 2011 14:27:11 +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 Reviewed-by: Jeff Layton --- fs/cifs/cifsfs.c | 18 +++++++----------- 1 files changed, 7 insertions(+), 11 deletions(-) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index fb6a2ad..cf8a610 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -134,24 +134,20 @@ 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_CACHE_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