diff mbox

[v2] NFS: Reduce stack use in encode_exchange_id()

Message ID 1353107526-25460-1-git-send-email-rees@umich.edu (mailing list archive)
State New, archived
Headers show

Commit Message

Jim Rees Nov. 16, 2012, 11:12 p.m. UTC
encode_exchange_id() uses more stack space than necessary, giving a compile
time warning. Reduce the size of the static buffer for implementation name.

Signed-off-by: Jim Rees <rees@umich.edu>
Reviewed-by: "Adamson, Dros" <Weston.Adamson@netapp.com>
---
 fs/nfs/nfs4xdr.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Trond Myklebust Nov. 17, 2012, 12:53 a.m. UTC | #1
On Fri, 2012-11-16 at 18:12 -0500, Jim Rees wrote:
> encode_exchange_id() uses more stack space than necessary, giving a compile

> time warning. Reduce the size of the static buffer for implementation name.

> 

> Signed-off-by: Jim Rees <rees@umich.edu>

> Reviewed-by: "Adamson, Dros" <Weston.Adamson@netapp.com>

> ---

>  fs/nfs/nfs4xdr.c |    8 +++++---

>  1 file changed, 5 insertions(+), 3 deletions(-)

> 

> diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c

> index 672d9b0..cc2f8a9 100644

> --- a/fs/nfs/nfs4xdr.c

> +++ b/fs/nfs/nfs4xdr.c

> @@ -270,6 +270,8 @@ static int nfs4_stat_to_errno(int);

>  

>  #if defined(CONFIG_NFS_V4_1)

>  #define NFS4_MAX_MACHINE_NAME_LEN (64)

> +#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \

> +			 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)

>  

>  #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \

>  				encode_verifier_maxsz + \

> @@ -282,7 +284,7 @@ static int nfs4_stat_to_errno(int);

>  				1 /* nii_domain */ + \

>  				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \

>  				1 /* nii_name */ + \

> -				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \

> +				XDR_QUADLEN(IMPL_NAME_LIMIT) + \

>  				3 /* nii_date */)

>  #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \

>  				2 /* eir_clientid */ + \

> @@ -1711,7 +1713,7 @@ static void encode_exchange_id(struct xdr_stream *xdr,

>  			       struct compound_hdr *hdr)

>  {

>  	__be32 *p;

> -	char impl_name[NFS4_OPAQUE_LIMIT];

> +	char impl_name[IMPL_NAME_LIMIT];

>  	int len = 0;

>  

>  	encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);

> @@ -1726,7 +1728,7 @@ static void encode_exchange_id(struct xdr_stream *xdr,

>  	if (send_implementation_id &&

>  	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&

>  	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)

> -		<= NFS4_OPAQUE_LIMIT + 1)

> +		<= sizeof(impl_name) + 1)

>  		len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",

>  			       utsname()->sysname, utsname()->release,

>  			       utsname()->version, utsname()->machine);


Thanks Jim! I will apply...

-- 
Trond Myklebust
Linux NFS client maintainer

NetApp
Trond.Myklebust@netapp.com
www.netapp.com
diff mbox

Patch

diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 672d9b0..cc2f8a9 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -270,6 +270,8 @@  static int nfs4_stat_to_errno(int);
 
 #if defined(CONFIG_NFS_V4_1)
 #define NFS4_MAX_MACHINE_NAME_LEN (64)
+#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
+			 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
 
 #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
 				encode_verifier_maxsz + \
@@ -282,7 +284,7 @@  static int nfs4_stat_to_errno(int);
 				1 /* nii_domain */ + \
 				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
 				1 /* nii_name */ + \
-				XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
+				XDR_QUADLEN(IMPL_NAME_LIMIT) + \
 				3 /* nii_date */)
 #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
 				2 /* eir_clientid */ + \
@@ -1711,7 +1713,7 @@  static void encode_exchange_id(struct xdr_stream *xdr,
 			       struct compound_hdr *hdr)
 {
 	__be32 *p;
-	char impl_name[NFS4_OPAQUE_LIMIT];
+	char impl_name[IMPL_NAME_LIMIT];
 	int len = 0;
 
 	encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
@@ -1726,7 +1728,7 @@  static void encode_exchange_id(struct xdr_stream *xdr,
 	if (send_implementation_id &&
 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
 	    sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
-		<= NFS4_OPAQUE_LIMIT + 1)
+		<= sizeof(impl_name) + 1)
 		len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
 			       utsname()->sysname, utsname()->release,
 			       utsname()->version, utsname()->machine);