From patchwork Tue Oct 29 20:54:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Geyslan G. Bem" X-Patchwork-Id: 3111641 Return-Path: X-Original-To: patchwork-v9fs-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4F07F9F3E2 for ; Tue, 29 Oct 2013 20:59:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 720FD2018B for ; Tue, 29 Oct 2013 20:59:48 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 446372017E for ; Tue, 29 Oct 2013 20:59:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1VbGNz-0002Pt-Qd; Tue, 29 Oct 2013 20:59:35 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1VbGNy-0002Po-2V for v9fs-developer@lists.sourceforge.net; Tue, 29 Oct 2013 20:59:34 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of gmail.com designates 209.85.161.172 as permitted sender) client-ip=209.85.161.172; envelope-from=geyslan@gmail.com; helo=mail-gg0-f172.google.com; Received: from mail-gg0-f172.google.com ([209.85.161.172]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1VbGNx-0002HB-9k for v9fs-developer@lists.sourceforge.net; Tue, 29 Oct 2013 20:59:34 +0000 Received: by mail-gg0-f172.google.com with SMTP id k3so173607ggn.17 for ; Tue, 29 Oct 2013 13:59:27 -0700 (PDT) X-Received: by 10.236.134.137 with SMTP id s9mr850577yhi.133.1383080367628; Tue, 29 Oct 2013 13:59:27 -0700 (PDT) Received: from localhost.localdomain (189-48-119-91.user.veloxzone.com.br. [189.48.119.91]) by mx.google.com with ESMTPSA id d26sm42590924yhj.25.2013.10.29.13.59.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Oct 2013 13:59:26 -0700 (PDT) From: "Geyslan G. Bem" To: kernel-br@googlegroups.com Date: Tue, 29 Oct 2013 17:54:37 -0300 Message-Id: <1383080077-16071-1-git-send-email-geyslan@gmail.com> X-Mailer: git-send-email 1.8.4 X-Spam-Score: -1.6 (-) X-Headers-End: 1VbGNx-0002HB-9k Cc: Latchesar Ionkov , "Geyslan G. Bem" , Eric Van Hensbergen , open list , "open list:9P FILE SYSTEM" , Ron Minnich Subject: [V9fs-developer] [PATCH] 9p: code refactor in vfs_inode.c X-BeenThere: v9fs-developer@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: v9fs-developer-bounces@lists.sourceforge.net X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In unixmode2p9mode(): Change 'res' type from int to u32. In p9mode2unixmode(): Change 'res' type from int to umode_t. Add sscanf() return value check and p9_debug() when error. Add possibility to call it passing NULL to rdev parameter. Only make device if 'rdev' pointer isn't NULL. Set '-EIO' to rdev if error when P9_DMDEVICE. Centralize return. In v9fs_test_inode(): Change 'umode' type from int to umode_t. Remove now useless 'rdev'. In v9fs_qid_iget(): Return rdev if 'IS_ERR_VALUE(rdev)' is true after call p9mode2unixmode(). In v9fs_refresh_inode(): Change 'umode' type from int to umode_t. Remove now useless 'rdev'. Signed-off-by: Geyslan G. Bem --- fs/9p/vfs_inode.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index 94de6d1..e3d56f1 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -63,7 +63,7 @@ static const struct inode_operations v9fs_symlink_inode_operations; static u32 unixmode2p9mode(struct v9fs_session_info *v9ses, umode_t mode) { - int res; + u32 res; res = mode & 0777; if (S_ISDIR(mode)) res |= P9_DMDIR; @@ -125,10 +125,9 @@ static int p9mode2perm(struct v9fs_session_info *v9ses, static umode_t p9mode2unixmode(struct v9fs_session_info *v9ses, struct p9_wstat *stat, dev_t *rdev) { - int res; + umode_t res; u32 mode = stat->mode; - *rdev = 0; res = p9mode2perm(v9ses, stat); if ((mode & P9_DMDIR) == P9_DMDIR) @@ -144,10 +143,15 @@ static umode_t p9mode2unixmode(struct v9fs_session_info *v9ses, else if ((mode & P9_DMDEVICE) && (v9fs_proto_dotu(v9ses)) && (v9ses->nodev == 0)) { char type = 0, ext[32]; - int major = -1, minor = -1; + u32 major = 0, minor = 0; strlcpy(ext, stat->extension, sizeof(ext)); - sscanf(ext, "%c %u %u", &type, &major, &minor); + if (sscanf(ext, "%c %u %u", &type, &major, &minor) < 3) { + p9_debug(P9_DEBUG_ERROR, + "It's necessary define type [%c], major [%u] and minor [%u]" \ + "values when mode is P9_DMDEVICE\n", type, major, minor); + goto err_dev; + } switch (type) { case 'c': res |= S_IFCHR; @@ -158,11 +162,18 @@ static umode_t p9mode2unixmode(struct v9fs_session_info *v9ses, default: p9_debug(P9_DEBUG_ERROR, "Unknown special type %c %s\n", type, stat->extension); - }; - *rdev = MKDEV(major, minor); + goto err_dev; + } + /* Only make device if rdev pointer isn't NULL */ + if (rdev) + *rdev = MKDEV(major, minor); } else res |= S_IFREG; - + goto ret; +err_dev: + if (rdev) + rdev = ERR_PTR(-EIO); +ret: return res; } @@ -460,13 +471,12 @@ void v9fs_evict_inode(struct inode *inode) static int v9fs_test_inode(struct inode *inode, void *data) { - int umode; - dev_t rdev; + umode_t umode; struct v9fs_inode *v9inode = V9FS_I(inode); struct p9_wstat *st = (struct p9_wstat *)data; struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); - umode = p9mode2unixmode(v9ses, st, &rdev); + umode = p9mode2unixmode(v9ses, st, NULL); /* don't match inode of different type */ if ((inode->i_mode & S_IFMT) != (umode & S_IFMT)) return 0; @@ -526,6 +536,10 @@ static struct inode *v9fs_qid_iget(struct super_block *sb, */ inode->i_ino = i_ino; umode = p9mode2unixmode(v9ses, st, &rdev); + if (IS_ERR_VALUE(rdev)) { + retval = rdev; + goto error; + } retval = v9fs_init_inode(v9ses, inode, umode, rdev); if (retval) goto error; @@ -1461,8 +1475,7 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t rde int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode) { - int umode; - dev_t rdev; + umode_t umode; loff_t i_size; struct p9_wstat *st; struct v9fs_session_info *v9ses; @@ -1474,7 +1487,7 @@ int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode) /* * Don't update inode if the file type is different */ - umode = p9mode2unixmode(v9ses, st, &rdev); + umode = p9mode2unixmode(v9ses, st, NULL); if ((inode->i_mode & S_IFMT) != (umode & S_IFMT)) goto out;