Skip to contentSkip to conversation

orangefs: use memcpy_and_pad in khandle_to and inode_getxattr

PATCH RESEND In review Thorsten Blum 2 participants 2 messages May 4 – May 5 Orangefs filesystem

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 orangefs: use memcpy_and_pad in khandle_to and inode_getxattr

Use memcpy_and_pad() instead of memcpy() followed by memset() to simplify ORANGEFS_khandle_to() and orangefs_inode_getxattr().

---
 fs/orangefs/protocol.h | 5 +----
 fs/orangefs/xattr.c    | 6 ++----
 2 files changed, 3 insertions(+), 8 deletions(-)
fs/orangefs/protocol.h +1 -4
index d403cf29a99b..bbdbd6a05d0d 100644
@@ -50,10 +50,7 @@ static inline int ORANGEFS_khandle_cmp(const struct orangefs_khandle *kh1,
 static inline void ORANGEFS_khandle_to(const struct orangefs_khandle *kh,
 				   void *p, int size)
 {
-
-	memcpy(p, kh->u, 16);
-	memset(p + 16, 0, size - 16);
-
+	memcpy_and_pad(p, size, kh->u, 16, 0);
 }
 
 static inline void ORANGEFS_khandle_from(struct orangefs_khandle *kh,
fs/orangefs/xattr.c +2 -4
index b6d116302de4..5c061603b29b 100644
@@ -140,8 +140,7 @@ ssize_t orangefs_inode_getxattr(struct inode *inode, const char *name,
 				ret = -ERANGE;
 				goto out_unlock;
 			}
-			memcpy(buffer, cx->val, cx->length);
-			memset(buffer + cx->length, 0, size - cx->length);
+			memcpy_and_pad(buffer, size, cx->val, cx->length, 0);
 			ret = cx->length;
 			goto out_unlock;
 		}
@@ -209,8 +208,7 @@ ssize_t orangefs_inode_getxattr(struct inode *inode, const char *name,
 		goto out_release_op;
 	}
 
-	memcpy(buffer, new_op->downcall.resp.getxattr.val, length);
-	memset(buffer + length, 0, size - length);
+	memcpy_and_pad(buffer, size, new_op->downcall.resp.getxattr.val, length, 0);
 	gossip_debug(GOSSIP_XATTR_DEBUG,
 	     "orangefs_inode_getxattr: inode %pU "
 	     "key %s key_sz %d, val_len %d\n",
maintainer
#1 lore raw

Thanks... looks good... I'll add it to my next
xfstests run...

-Mike

Quoted 50 lines · Thorsten Blum

Use memcpy_and_pad() instead of memcpy() followed by memset() to simplify ORANGEFS_khandle_to() and orangefs_inode_getxattr().

---
 fs/orangefs/protocol.h | 5 +----
 fs/orangefs/xattr.c    | 6 ++----
 2 files changed, 3 insertions(+), 8 deletions(-)
fs/orangefs/protocol.h +1 -4
index d403cf29a99b..bbdbd6a05d0d 100644
@@ -50,10 +50,7 @@ static inline int ORANGEFS_khandle_cmp(const struct orangefs_khandle *kh1,
 static inline void ORANGEFS_khandle_to(const struct orangefs_khandle *kh,
                                   void *p, int size)
 {
-
-       memcpy(p, kh->u, 16);
-       memset(p + 16, 0, size - 16);
-
+       memcpy_and_pad(p, size, kh->u, 16, 0);
 }
 
 static inline void ORANGEFS_khandle_from(struct orangefs_khandle *kh,
fs/orangefs/xattr.c +2 -4
index b6d116302de4..5c061603b29b 100644
@@ -140,8 +140,7 @@ ssize_t orangefs_inode_getxattr(struct inode *inode, const char *name,
                                ret = -ERANGE;
                                goto out_unlock;
                        }
-                       memcpy(buffer, cx->val, cx->length);
-                       memset(buffer + cx->length, 0, size - cx->length);
+                       memcpy_and_pad(buffer, size, cx->val, cx->length, 0);
                        ret = cx->length;
                        goto out_unlock;
                }
@@ -209,8 +208,7 @@ ssize_t orangefs_inode_getxattr(struct inode *inode, const char *name,
                goto out_release_op;
        }
 
-       memcpy(buffer, new_op->downcall.resp.getxattr.val, length);
-       memset(buffer + length, 0, size - length);
+       memcpy_and_pad(buffer, size, new_op->downcall.resp.getxattr.val, length, 0);
        gossip_debug(GOSSIP_XATTR_DEBUG,
             "orangefs_inode_getxattr: inode %pU "
             "key %s key_sz %d, val_len %d\n",