linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] fs/xfs: replace strncpy with memtostr_pad()
@ 2025-07-04 10:12 Pranav Tyagi
  2025-07-10 10:26 ` Pranav Tyagi
  2025-07-17  8:11 ` Carlos Maiolino
  0 siblings, 2 replies; 5+ messages in thread
From: Pranav Tyagi @ 2025-07-04 10:12 UTC (permalink / raw)
  To: linux-xfs, linux-kernel
  Cc: cem, djwong, skhan, linux-kernel-mentees, Pranav Tyagi

Replace the deprecated strncpy() with memtostr_pad(). This also avoids
the need for separate zeroing using memset(). Mark sb_fname buffer with
__nonstring as its size is XFSLABEL_MAX and so no terminating NULL for
sb_fname.

Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
---
 fs/xfs/libxfs/xfs_format.h | 2 +-
 fs/xfs/xfs_ioctl.c         | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index 9566a7623365..779dac59b1f3 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -112,7 +112,7 @@ typedef struct xfs_sb {
 	uint16_t	sb_sectsize;	/* volume sector size, bytes */
 	uint16_t	sb_inodesize;	/* inode size, bytes */
 	uint16_t	sb_inopblock;	/* inodes per block */
-	char		sb_fname[XFSLABEL_MAX]; /* file system name */
+	char		sb_fname[XFSLABEL_MAX] __nonstring; /* file system name */
 	uint8_t		sb_blocklog;	/* log2 of sb_blocksize */
 	uint8_t		sb_sectlog;	/* log2 of sb_sectsize */
 	uint8_t		sb_inodelog;	/* log2 of sb_inodesize */
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index d250f7f74e3b..c3e8c5c1084f 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -990,9 +990,8 @@ xfs_ioc_getlabel(
 	BUILD_BUG_ON(sizeof(sbp->sb_fname) > FSLABEL_MAX);
 
 	/* 1 larger than sb_fname, so this ensures a trailing NUL char */
-	memset(label, 0, sizeof(label));
 	spin_lock(&mp->m_sb_lock);
-	strncpy(label, sbp->sb_fname, XFSLABEL_MAX);
+	memtostr_pad(label, sbp->sb_fname);
 	spin_unlock(&mp->m_sb_lock);
 
 	if (copy_to_user(user_label, label, sizeof(label)))
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] fs/xfs: replace strncpy with memtostr_pad()
  2025-07-04 10:12 [PATCH v2] fs/xfs: replace strncpy with memtostr_pad() Pranav Tyagi
@ 2025-07-10 10:26 ` Pranav Tyagi
  2025-07-12  5:56   ` Darrick J. Wong
  2025-07-15  8:41   ` Carlos Maiolino
  2025-07-17  8:11 ` Carlos Maiolino
  1 sibling, 2 replies; 5+ messages in thread
From: Pranav Tyagi @ 2025-07-10 10:26 UTC (permalink / raw)
  To: linux-xfs, linux-kernel; +Cc: cem, djwong, skhan, linux-kernel-mentees

On Fri, Jul 4, 2025 at 3:42 PM Pranav Tyagi <pranav.tyagi03@gmail.com> wrote:
>
> Replace the deprecated strncpy() with memtostr_pad(). This also avoids
> the need for separate zeroing using memset(). Mark sb_fname buffer with
> __nonstring as its size is XFSLABEL_MAX and so no terminating NULL for
> sb_fname.
>
> Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
> ---
>  fs/xfs/libxfs/xfs_format.h | 2 +-
>  fs/xfs/xfs_ioctl.c         | 3 +--
>  2 files changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
> index 9566a7623365..779dac59b1f3 100644
> --- a/fs/xfs/libxfs/xfs_format.h
> +++ b/fs/xfs/libxfs/xfs_format.h
> @@ -112,7 +112,7 @@ typedef struct xfs_sb {
>         uint16_t        sb_sectsize;    /* volume sector size, bytes */
>         uint16_t        sb_inodesize;   /* inode size, bytes */
>         uint16_t        sb_inopblock;   /* inodes per block */
> -       char            sb_fname[XFSLABEL_MAX]; /* file system name */
> +       char            sb_fname[XFSLABEL_MAX] __nonstring; /* file system name */
>         uint8_t         sb_blocklog;    /* log2 of sb_blocksize */
>         uint8_t         sb_sectlog;     /* log2 of sb_sectsize */
>         uint8_t         sb_inodelog;    /* log2 of sb_inodesize */
> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index d250f7f74e3b..c3e8c5c1084f 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -990,9 +990,8 @@ xfs_ioc_getlabel(
>         BUILD_BUG_ON(sizeof(sbp->sb_fname) > FSLABEL_MAX);
>
>         /* 1 larger than sb_fname, so this ensures a trailing NUL char */
> -       memset(label, 0, sizeof(label));
>         spin_lock(&mp->m_sb_lock);
> -       strncpy(label, sbp->sb_fname, XFSLABEL_MAX);
> +       memtostr_pad(label, sbp->sb_fname);
>         spin_unlock(&mp->m_sb_lock);
>
>         if (copy_to_user(user_label, label, sizeof(label)))
> --
> 2.49.0
>
Hi,

This is a gentle follow-up on this patch. I would like to
know if there is any update on its state.

Regards
Pranav Tyagi

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] fs/xfs: replace strncpy with memtostr_pad()
  2025-07-10 10:26 ` Pranav Tyagi
@ 2025-07-12  5:56   ` Darrick J. Wong
  2025-07-15  8:41   ` Carlos Maiolino
  1 sibling, 0 replies; 5+ messages in thread
From: Darrick J. Wong @ 2025-07-12  5:56 UTC (permalink / raw)
  To: Pranav Tyagi; +Cc: linux-xfs, linux-kernel, cem, skhan, linux-kernel-mentees

On Thu, Jul 10, 2025 at 03:56:01PM +0530, Pranav Tyagi wrote:
> On Fri, Jul 4, 2025 at 3:42 PM Pranav Tyagi <pranav.tyagi03@gmail.com> wrote:
> >
> > Replace the deprecated strncpy() with memtostr_pad(). This also avoids
> > the need for separate zeroing using memset(). Mark sb_fname buffer with
> > __nonstring as its size is XFSLABEL_MAX and so no terminating NULL for
> > sb_fname.
> >
> > Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
> > ---
> >  fs/xfs/libxfs/xfs_format.h | 2 +-
> >  fs/xfs/xfs_ioctl.c         | 3 +--
> >  2 files changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
> > index 9566a7623365..779dac59b1f3 100644
> > --- a/fs/xfs/libxfs/xfs_format.h
> > +++ b/fs/xfs/libxfs/xfs_format.h
> > @@ -112,7 +112,7 @@ typedef struct xfs_sb {
> >         uint16_t        sb_sectsize;    /* volume sector size, bytes */
> >         uint16_t        sb_inodesize;   /* inode size, bytes */
> >         uint16_t        sb_inopblock;   /* inodes per block */
> > -       char            sb_fname[XFSLABEL_MAX]; /* file system name */
> > +       char            sb_fname[XFSLABEL_MAX] __nonstring; /* file system name */
> >         uint8_t         sb_blocklog;    /* log2 of sb_blocksize */
> >         uint8_t         sb_sectlog;     /* log2 of sb_sectsize */
> >         uint8_t         sb_inodelog;    /* log2 of sb_inodesize */
> > diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> > index d250f7f74e3b..c3e8c5c1084f 100644
> > --- a/fs/xfs/xfs_ioctl.c
> > +++ b/fs/xfs/xfs_ioctl.c
> > @@ -990,9 +990,8 @@ xfs_ioc_getlabel(
> >         BUILD_BUG_ON(sizeof(sbp->sb_fname) > FSLABEL_MAX);
> >
> >         /* 1 larger than sb_fname, so this ensures a trailing NUL char */
> > -       memset(label, 0, sizeof(label));
> >         spin_lock(&mp->m_sb_lock);
> > -       strncpy(label, sbp->sb_fname, XFSLABEL_MAX);
> > +       memtostr_pad(label, sbp->sb_fname);
> >         spin_unlock(&mp->m_sb_lock);
> >
> >         if (copy_to_user(user_label, label, sizeof(label)))
> > --
> > 2.49.0
> >
> Hi,
> 
> This is a gentle follow-up on this patch. I would like to
> know if there is any update on its state.

Seems fine to me...
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> 
> Regards
> Pranav Tyagi
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] fs/xfs: replace strncpy with memtostr_pad()
  2025-07-10 10:26 ` Pranav Tyagi
  2025-07-12  5:56   ` Darrick J. Wong
@ 2025-07-15  8:41   ` Carlos Maiolino
  1 sibling, 0 replies; 5+ messages in thread
From: Carlos Maiolino @ 2025-07-15  8:41 UTC (permalink / raw)
  To: Pranav Tyagi; +Cc: linux-xfs, linux-kernel, djwong, skhan, linux-kernel-mentees

On Thu, Jul 10, 2025 at 03:56:01PM +0530, Pranav Tyagi wrote:
> On Fri, Jul 4, 2025 at 3:42 PM Pranav Tyagi <pranav.tyagi03@gmail.com> wrote:
> >
> > Replace the deprecated strncpy() with memtostr_pad(). This also avoids
> > the need for separate zeroing using memset(). Mark sb_fname buffer with
> > __nonstring as its size is XFSLABEL_MAX and so no terminating NULL for
> > sb_fname.
> >
> > Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
> > ---
> >  fs/xfs/libxfs/xfs_format.h | 2 +-
> >  fs/xfs/xfs_ioctl.c         | 3 +--
> >  2 files changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
> > index 9566a7623365..779dac59b1f3 100644
> > --- a/fs/xfs/libxfs/xfs_format.h
> > +++ b/fs/xfs/libxfs/xfs_format.h
> > @@ -112,7 +112,7 @@ typedef struct xfs_sb {
> >         uint16_t        sb_sectsize;    /* volume sector size, bytes */
> >         uint16_t        sb_inodesize;   /* inode size, bytes */
> >         uint16_t        sb_inopblock;   /* inodes per block */
> > -       char            sb_fname[XFSLABEL_MAX]; /* file system name */
> > +       char            sb_fname[XFSLABEL_MAX] __nonstring; /* file system name */
> >         uint8_t         sb_blocklog;    /* log2 of sb_blocksize */
> >         uint8_t         sb_sectlog;     /* log2 of sb_sectsize */
> >         uint8_t         sb_inodelog;    /* log2 of sb_inodesize */
> > diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> > index d250f7f74e3b..c3e8c5c1084f 100644
> > --- a/fs/xfs/xfs_ioctl.c
> > +++ b/fs/xfs/xfs_ioctl.c
> > @@ -990,9 +990,8 @@ xfs_ioc_getlabel(
> >         BUILD_BUG_ON(sizeof(sbp->sb_fname) > FSLABEL_MAX);
> >
> >         /* 1 larger than sb_fname, so this ensures a trailing NUL char */
> > -       memset(label, 0, sizeof(label));
> >         spin_lock(&mp->m_sb_lock);
> > -       strncpy(label, sbp->sb_fname, XFSLABEL_MAX);
> > +       memtostr_pad(label, sbp->sb_fname);
> >         spin_unlock(&mp->m_sb_lock);
> >
> >         if (copy_to_user(user_label, label, sizeof(label)))
> > --
> > 2.49.0
> >
> Hi,
> 
> This is a gentle follow-up on this patch. I would like to
> know if there is any update on its state.

Looks fine to me:

Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>


> 
> Regards
> Pranav Tyagi
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] fs/xfs: replace strncpy with memtostr_pad()
  2025-07-04 10:12 [PATCH v2] fs/xfs: replace strncpy with memtostr_pad() Pranav Tyagi
  2025-07-10 10:26 ` Pranav Tyagi
@ 2025-07-17  8:11 ` Carlos Maiolino
  1 sibling, 0 replies; 5+ messages in thread
From: Carlos Maiolino @ 2025-07-17  8:11 UTC (permalink / raw)
  To: linux-xfs, linux-kernel, Pranav Tyagi; +Cc: djwong, skhan, linux-kernel-mentees

On Fri, 04 Jul 2025 15:42:50 +0530, Pranav Tyagi wrote:
> Replace the deprecated strncpy() with memtostr_pad(). This also avoids
> the need for separate zeroing using memset(). Mark sb_fname buffer with
> __nonstring as its size is XFSLABEL_MAX and so no terminating NULL for
> sb_fname.
> 
> 

Applied to for-next, thanks!

[1/1] fs/xfs: replace strncpy with memtostr_pad()
      commit: f161da9418910f4ab7a29099682d03e06ef2c3ef

Best regards,
-- 
Carlos Maiolino <cem@kernel.org>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-07-17  8:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-04 10:12 [PATCH v2] fs/xfs: replace strncpy with memtostr_pad() Pranav Tyagi
2025-07-10 10:26 ` Pranav Tyagi
2025-07-12  5:56   ` Darrick J. Wong
2025-07-15  8:41   ` Carlos Maiolino
2025-07-17  8:11 ` Carlos Maiolino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).