From patchwork Fri Sep 4 11:57:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Andreas_Gr=C3=BCnbacher?= X-Patchwork-Id: 7121621 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5126F9F32B for ; Fri, 4 Sep 2015 11:59:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4440E200D0 for ; Fri, 4 Sep 2015 11:59:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1FE9B2079F for ; Fri, 4 Sep 2015 11:59:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758782AbbIDL6f (ORCPT ); Fri, 4 Sep 2015 07:58:35 -0400 Received: from mail-wi0-f179.google.com ([209.85.212.179]:38324 "EHLO mail-wi0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751311AbbIDL5f (ORCPT ); Fri, 4 Sep 2015 07:57:35 -0400 Received: by wiclk2 with SMTP id lk2so15454614wic.1; Fri, 04 Sep 2015 04:57:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=xO8MZUMdghJL0pyr+9uwD0jQwjWDiPyJScp0adz0mDg=; b=mlVQ94n9zw5+XKyytGwwuXjK4VmqcTM+r/tR/NDvJ7xsQLID54GD8eIDQYBGXzIcTt NExL72vJjPLEXBsGs6yIJAHfM0CpKSST0n6FYjHQdHv1SL621HG9UXhOKD6lrEr/hUVM LqXi86bZtctm2SxOJ9ZavP0Q00T+7YPteki0MizbNnPa9FR47ASRepvvvQWwnDMnes6f Ju4H4txg0rmoeLZC46V03q9VrgfIJtbQ+w2m/x5EZglnvJlDezv3vpN6kmfh+x4IfNIQ W5MQlEndlfoafkCDnYXwLBxLAokBtPDksLDDsYNTG+3VQAB5eNtpW3xqFjX/0p+QQdPC DeVw== X-Received: by 10.180.81.227 with SMTP id d3mr6668820wiy.38.1441367854451; Fri, 04 Sep 2015 04:57:34 -0700 (PDT) Received: from nuc.lan ([95.91.235.105]) by smtp.gmail.com with ESMTPSA id op6sm3940943wic.12.2015.09.04.04.57.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Sep 2015 04:57:33 -0700 (PDT) From: Andreas Gruenbacher X-Google-Original-From: Andreas Gruenbacher To: Alexander Viro , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Artem Bityutskiy , Adrian Hunter , linux-mtd@lists.infradead.org, Richard Weinberger , Eric Van Hensbergen , Ron Minnich , Latchesar Ionkov , v9fs-developer@lists.sourceforge.net Subject: [PATCH 3/5] 9p: Simplify the xattr handlers Date: Fri, 4 Sep 2015 13:57:20 +0200 Message-Id: <1441367842-25079-4-git-send-email-agruenba@redhat.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1441367842-25079-1-git-send-email-agruenba@redhat.com> References: <1441367842-25079-1-git-send-email-agruenba@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 The generic_{get,set,remove}xattr inode operations use the xattr name prefix to decide which of the defined xattr handlers to call, then call the appropriate handler's get or set operation. The name suffix is passed to the get or set operations, the prefix is still "there" in the name before the suffix though. There is no need to recompose the name in a temporary buffer. Signed-off-by: Andreas Gruenbacher --- fs/9p/xattr_security.c | 34 ++++------------------------------ fs/9p/xattr_trusted.c | 34 ++++------------------------------ fs/9p/xattr_user.c | 34 ++++------------------------------ 3 files changed, 12 insertions(+), 90 deletions(-) diff --git a/fs/9p/xattr_security.c b/fs/9p/xattr_security.c index cb247a1..2c9b394 100644 --- a/fs/9p/xattr_security.c +++ b/fs/9p/xattr_security.c @@ -22,10 +22,7 @@ static int v9fs_xattr_security_get(struct dentry *dentry, const char *name, void *buffer, size_t size, int type) { - int retval; - char *full_name; - size_t name_len; - size_t prefix_len = XATTR_SECURITY_PREFIX_LEN; + const char *full_name = name - XATTR_SECURITY_PREFIX_LEN; if (name == NULL) return -EINVAL; @@ -33,26 +30,13 @@ static int v9fs_xattr_security_get(struct dentry *dentry, const char *name, if (strcmp(name, "") == 0) return -EINVAL; - name_len = strlen(name); - full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL); - if (!full_name) - return -ENOMEM; - memcpy(full_name, XATTR_SECURITY_PREFIX, prefix_len); - memcpy(full_name+prefix_len, name, name_len); - full_name[prefix_len + name_len] = '\0'; - - retval = v9fs_xattr_get(dentry, full_name, buffer, size); - kfree(full_name); - return retval; + return v9fs_xattr_get(dentry, full_name, buffer, size); } static int v9fs_xattr_security_set(struct dentry *dentry, const char *name, const void *value, size_t size, int flags, int type) { - int retval; - char *full_name; - size_t name_len; - size_t prefix_len = XATTR_SECURITY_PREFIX_LEN; + const char *full_name = name - XATTR_SECURITY_PREFIX_LEN; if (name == NULL) return -EINVAL; @@ -60,17 +44,7 @@ static int v9fs_xattr_security_set(struct dentry *dentry, const char *name, if (strcmp(name, "") == 0) return -EINVAL; - name_len = strlen(name); - full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL); - if (!full_name) - return -ENOMEM; - memcpy(full_name, XATTR_SECURITY_PREFIX, prefix_len); - memcpy(full_name + prefix_len, name, name_len); - full_name[prefix_len + name_len] = '\0'; - - retval = v9fs_xattr_set(dentry, full_name, value, size, flags); - kfree(full_name); - return retval; + return v9fs_xattr_set(dentry, full_name, value, size, flags); } struct xattr_handler v9fs_xattr_security_handler = { diff --git a/fs/9p/xattr_trusted.c b/fs/9p/xattr_trusted.c index e30d33b..ee470b6 100644 --- a/fs/9p/xattr_trusted.c +++ b/fs/9p/xattr_trusted.c @@ -22,10 +22,7 @@ static int v9fs_xattr_trusted_get(struct dentry *dentry, const char *name, void *buffer, size_t size, int type) { - int retval; - char *full_name; - size_t name_len; - size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN; + const char *full_name = name - XATTR_TRUSTED_PREFIX_LEN; if (name == NULL) return -EINVAL; @@ -33,26 +30,13 @@ static int v9fs_xattr_trusted_get(struct dentry *dentry, const char *name, if (strcmp(name, "") == 0) return -EINVAL; - name_len = strlen(name); - full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL); - if (!full_name) - return -ENOMEM; - memcpy(full_name, XATTR_TRUSTED_PREFIX, prefix_len); - memcpy(full_name+prefix_len, name, name_len); - full_name[prefix_len + name_len] = '\0'; - - retval = v9fs_xattr_get(dentry, full_name, buffer, size); - kfree(full_name); - return retval; + return v9fs_xattr_get(dentry, full_name, buffer, size); } static int v9fs_xattr_trusted_set(struct dentry *dentry, const char *name, const void *value, size_t size, int flags, int type) { - int retval; - char *full_name; - size_t name_len; - size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN; + const char *full_name = name - XATTR_TRUSTED_PREFIX_LEN; if (name == NULL) return -EINVAL; @@ -60,17 +44,7 @@ static int v9fs_xattr_trusted_set(struct dentry *dentry, const char *name, if (strcmp(name, "") == 0) return -EINVAL; - name_len = strlen(name); - full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL); - if (!full_name) - return -ENOMEM; - memcpy(full_name, XATTR_TRUSTED_PREFIX, prefix_len); - memcpy(full_name + prefix_len, name, name_len); - full_name[prefix_len + name_len] = '\0'; - - retval = v9fs_xattr_set(dentry, full_name, value, size, flags); - kfree(full_name); - return retval; + return v9fs_xattr_set(dentry, full_name, value, size, flags); } struct xattr_handler v9fs_xattr_trusted_handler = { diff --git a/fs/9p/xattr_user.c b/fs/9p/xattr_user.c index d0b701b..4432604 100644 --- a/fs/9p/xattr_user.c +++ b/fs/9p/xattr_user.c @@ -22,10 +22,7 @@ static int v9fs_xattr_user_get(struct dentry *dentry, const char *name, void *buffer, size_t size, int type) { - int retval; - char *full_name; - size_t name_len; - size_t prefix_len = XATTR_USER_PREFIX_LEN; + const char *full_name = name - XATTR_USER_PREFIX_LEN; if (name == NULL) return -EINVAL; @@ -33,26 +30,13 @@ static int v9fs_xattr_user_get(struct dentry *dentry, const char *name, if (strcmp(name, "") == 0) return -EINVAL; - name_len = strlen(name); - full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL); - if (!full_name) - return -ENOMEM; - memcpy(full_name, XATTR_USER_PREFIX, prefix_len); - memcpy(full_name+prefix_len, name, name_len); - full_name[prefix_len + name_len] = '\0'; - - retval = v9fs_xattr_get(dentry, full_name, buffer, size); - kfree(full_name); - return retval; + return v9fs_xattr_get(dentry, full_name, buffer, size); } static int v9fs_xattr_user_set(struct dentry *dentry, const char *name, const void *value, size_t size, int flags, int type) { - int retval; - char *full_name; - size_t name_len; - size_t prefix_len = XATTR_USER_PREFIX_LEN; + const char *full_name = name - XATTR_USER_PREFIX_LEN; if (name == NULL) return -EINVAL; @@ -60,17 +44,7 @@ static int v9fs_xattr_user_set(struct dentry *dentry, const char *name, if (strcmp(name, "") == 0) return -EINVAL; - name_len = strlen(name); - full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL); - if (!full_name) - return -ENOMEM; - memcpy(full_name, XATTR_USER_PREFIX, prefix_len); - memcpy(full_name + prefix_len, name, name_len); - full_name[prefix_len + name_len] = '\0'; - - retval = v9fs_xattr_set(dentry, full_name, value, size, flags); - kfree(full_name); - return retval; + return v9fs_xattr_set(dentry, full_name, value, size, flags); } struct xattr_handler v9fs_xattr_user_handler = {