All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] sunrpc: Use "%*phN" to dprintk() a cookie
@ 2026-06-08 21:20 David Laight
  2026-06-09  0:33 ` Chuck Lever
  0 siblings, 1 reply; 2+ messages in thread
From: David Laight @ 2026-06-08 21:20 UTC (permalink / raw)
  To: Chuck Lever, Jeff Layton, NeilBrown, Olga Kornievskaia, Dai Ngo,
	Tom Talpey, Trond Myklebust, Anna Schumaker, linux-nfs,
	linux-kernel
  Cc: David Laight, Geert Uytterhoeven, Andy Shevchenko

Simplifies the code and removes a 'not obviously bounded' strcpy().

Delete the local function nlmdbg_cookie2a() that did the equivalent.

There is no need to worry about cookie->len being more than
NLM_MAXCOOKIELEN (32), the buffer holding it is only that long.
The existing length checks must pre-date this code being added in 2.4.26.

Signed-off-by: David Laight <david.laight.linux@gmail.com>
---

Found by a local build that errors strcpy() unless a constant string
is being written into an array.

 fs/lockd/svclock.c | 42 +++++-------------------------------------
 1 file changed, 5 insertions(+), 37 deletions(-)

diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index b98b1d0ada35..bcf261078aba 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -47,40 +47,6 @@ static const struct rpc_call_ops nlmsvc_grant_ops;
 static LIST_HEAD(nlm_blocked);
 static DEFINE_SPINLOCK(nlm_blocked_lock);
 
-#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
-static const char *nlmdbg_cookie2a(const struct nlm_cookie *cookie)
-{
-	/*
-	 * We can get away with a static buffer because this is only called
-	 * from lockd, which is single-threaded.
-	 */
-	static char buf[2*NLM_MAXCOOKIELEN+1];
-	unsigned int i, len = sizeof(buf);
-	char *p = buf;
-
-	len--;	/* allow for trailing \0 */
-	if (len < 3)
-		return "???";
-	for (i = 0 ; i < cookie->len ; i++) {
-		if (len < 2) {
-			strcpy(p-3, "...");
-			break;
-		}
-		sprintf(p, "%02x", cookie->data[i]);
-		p += 2;
-		len -= 2;
-	}
-	*p = '\0';
-
-	return buf;
-}
-#else
-static inline const char *nlmdbg_cookie2a(const struct nlm_cookie *cookie)
-{
-	return "???";
-}
-#endif
-
 /*
  * Insert a blocked lock into the global list
  */
@@ -155,11 +121,12 @@ nlmsvc_lookup_block(struct nlm_file *file, struct nlm_lock *lock)
 	spin_lock(&nlm_blocked_lock);
 	list_for_each_entry(block, &nlm_blocked, b_list) {
 		fl = &block->b_call->a_args.lock.fl;
-		dprintk("lockd: check f=%p pd=%d %Ld-%Ld ty=%d cookie=%s\n",
+		dprintk("lockd: check f=%p pd=%d %Ld-%Ld ty=%d cookie=%*phN\n",
 				block->b_file, fl->c.flc_pid,
 				(long long)fl->fl_start,
 				(long long)fl->fl_end, fl->c.flc_type,
-				nlmdbg_cookie2a(&block->b_call->a_args.cookie));
+				block->b_call->a_args.cookie.len,
+				block->b_call->a_args.cookie.data);
 		if (block->b_file == file && nlm_compare_locks(fl, &lock->fl)) {
 			kref_get(&block->b_count);
 			spin_unlock(&nlm_blocked_lock);
@@ -198,7 +165,8 @@ nlmsvc_find_block(struct nlm_cookie *cookie)
 	return NULL;
 
 found:
-	dprintk("nlmsvc_find_block(%s): block=%p\n", nlmdbg_cookie2a(cookie), block);
+	dprintk("nlmsvc_find_block(%*phN): block=%p\n",
+		cookie->len, cookie->data, block);
 	kref_get(&block->b_count);
 	spin_unlock(&nlm_blocked_lock);
 	return block;
-- 
2.39.5


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

* Re: [PATCH 1/1] sunrpc: Use "%*phN" to dprintk() a cookie
  2026-06-08 21:20 [PATCH 1/1] sunrpc: Use "%*phN" to dprintk() a cookie David Laight
@ 2026-06-09  0:33 ` Chuck Lever
  0 siblings, 0 replies; 2+ messages in thread
From: Chuck Lever @ 2026-06-09  0:33 UTC (permalink / raw)
  To: Jeff Layton, NeilBrown, Olga Kornievskaia, Dai Ngo, Tom Talpey,
	Trond Myklebust, Anna Schumaker, linux-nfs, linux-kernel,
	David Laight
  Cc: Chuck Lever, Geert Uytterhoeven, Andy Shevchenko

From: Chuck Lever <chuck.lever@oracle.com>

On Mon, 08 Jun 2026 22:20:42 +0100, David Laight wrote:
> Simplifies the code and removes a 'not obviously bounded' strcpy().
> 
> Delete the local function nlmdbg_cookie2a() that did the equivalent.
> 
> There is no need to worry about cookie->len being more than
> NLM_MAXCOOKIELEN (32), the buffer holding it is only that long.
> The existing length checks must pre-date this code being added in 2.4.26.
> 
> [...]

Applied to nfsd-testing, thanks!

[1/1] lockd: Use "%*phN" to dprintk() a cookie
      commit: 926ef0ef7994232faab29e6b13270d5c88b058f3

--
Chuck Lever <chuck.lever@oracle.com>

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

end of thread, other threads:[~2026-06-09  0:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-08 21:20 [PATCH 1/1] sunrpc: Use "%*phN" to dprintk() a cookie David Laight
2026-06-09  0:33 ` Chuck Lever

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.