From patchwork Thu Aug 20 18:19:50 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: 7046431 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 7BAC49F372 for ; Thu, 20 Aug 2015 18:20:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 66EA020569 for ; Thu, 20 Aug 2015 18:20:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 46B992054D for ; Thu, 20 Aug 2015 18:20:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752218AbbHTSUt (ORCPT ); Thu, 20 Aug 2015 14:20:49 -0400 Received: from mail-wi0-f174.google.com ([209.85.212.174]:34261 "EHLO mail-wi0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752198AbbHTSUs (ORCPT ); Thu, 20 Aug 2015 14:20:48 -0400 Received: by wicne3 with SMTP id ne3so447801wic.1; Thu, 20 Aug 2015 11:20:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xO8MZUMdghJL0pyr+9uwD0jQwjWDiPyJScp0adz0mDg=; b=YNrpiGuknTNSfXUIj8UOfWojBwUQWjOq23m8Qwf93a4vZ5wn0/ndcmfZ7vbVtjxQOh 43Hi5Go6a0SjciooYk7ryzkRXHj4D912ASpw3iX0wb3c1Vwv7xfdn6D1FNORD3Bv94Kx dlyeI7Md7M66wic+3ZpsUmJfbBQoaIeLZU1Ek0MrRwNPq/YgU3GHfzIlng98xQH8h5CI NTWNietd9jUR+/M+JxAUIdDDqz/LCMAQV1vrvLD79XJylfsUT8NgQmTkyiZ1nT30wVQ9 ueOZTy87LeZnxYU7T0nadtvxOiZzI8xh+1n3MI+Qm0KqznLG40oEetLYlV4aXjIq3wTx o/+g== X-Received: by 10.194.237.232 with SMTP id vf8mr8479855wjc.22.1440094846776; Thu, 20 Aug 2015 11:20:46 -0700 (PDT) Received: from nuc.home.com (p549817FE.dip0.t-ipconnect.de. [84.152.23.254]) by smtp.gmail.com with ESMTPSA id ma4sm6598334wjb.38.2015.08.20.11.20.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Aug 2015 11:20:45 -0700 (PDT) From: Andreas Gruenbacher X-Google-Original-From: Andreas Gruenbacher To: Alexander Viro , Christoph Hellwig , Eric Paris , "Aneesh Kumar K.V" , linux-fsdevel@vger.kernel.org, David Quigley , "J. Bruce Fields" Cc: linux-security-module@vger.kernel.org, cluster-devel@redhat.com Subject: [RFC 03/11] 9p: Simplify the xattr handlers Date: Thu, 20 Aug 2015 20:19:50 +0200 Message-Id: <1440094798-1411-4-git-send-email-agruenba@redhat.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1440094798-1411-1-git-send-email-agruenba@redhat.com> References: <1440094798-1411-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=-7.4 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=ham 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 = {