Skip to contentSkip to conversation

Little fix that missed the merge window.

PATCH New Konrad Rzeszutek Wilk 4 participants 8 messages Feb 26, 2021 – Mar 4, 2021 CXL

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Little fix that missed the merge window.

When the last set of patches were posted for review right before the merge window this fix was deferred.

Please at your convience pick it up.

 drivers/cxl/mem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Konrad Rzeszutek Wilk (1):
cxl: Make loop variable be 'i' instead of 'j'

#1 lore raw

PATCH 1/1 cxl: Make loop variable be 'i' instead of 'j'

.. otherwise people spend extra cycles looking for the inner loop and wondering 'why j'?

This was an over-sight when initial work was rebased so lets fix it here.

Fixes 583fa5e71cae ("cxl/mem: Add basic IOCTL interface")
---
 drivers/cxl/mem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cxl/mem.c +3 -3
index 244cb7d89678..2b8265b03b0d 100644
@@ -698,7 +698,7 @@ static int cxl_query_cmd(struct cxl_memdev *cxlmd,
 	struct device *dev = &cxlmd->dev;
 	struct cxl_mem_command *cmd;
 	u32 n_commands;
-	int j = 0;
+	int i = 0;
 
 	dev_dbg(dev, "Query IOCTL\n");
 
@@ -716,10 +716,10 @@ static int cxl_query_cmd(struct cxl_memdev *cxlmd,
 	cxl_for_each_cmd(cmd) {
 		const struct cxl_command_info *info = &cmd->info;
 
-		if (copy_to_user(&q->commands[j++], info, sizeof(*info)))
+		if (copy_to_user(&q->commands[i++], info, sizeof(*info)))
 			return -EFAULT;
 
-		if (j == n_commands)
+		if (i == n_commands)
 			break;
 	}
 
Signature · 1 line
2.13.6
#2 lore raw

Re: [PATCH] cxl: Make loop variable be 'i' instead of 'j'

Quoted 1 line · Konrad Rzeszutek Wilk

Hey, Konrad, thanks for fixing this up. Some more cosmetic changes to fold in below...

Quoted 4 lines

.. otherwise people spend extra cycles looking for the inner loop and wondering 'why j'?

This was an over-sight when initial work was rebased

s/over-sight/oversight/

Quoted 1 line

so lets fix it here.

s/lets/let's/

Quoted 1 line
Fixes 583fa5e71cae ("cxl/mem: Add basic IOCTL interface")

Since it's just cosmetic, I don't think it needs a "Fixes:". The AUTOSEL-bot need not worry about this.

Quoted 10 lines
---
 drivers/cxl/mem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cxl/mem.c +0 -0
index 244cb7d89678..2b8265b03b0d 100644

drivers/cxl/mem.c static int cxl_query_cmd(struct cxl_memdev *cxlmd, · line 701

Quoted 5 lines
drivers/cxl/mem.c +1 -1
@@ -698,7 +698,7 @@ static int cxl_query_cmd(struct cxl_memdev *cxlmd,
        struct device *dev = &cxlmd->dev;
        struct cxl_mem_command *cmd;
        u32 n_commands;
-       int j = 0;
+       int i = 0;

Let's move this initialization down to right before the loop. If this ever gets refactored and @i gets reused this will break.

Quoted 19 lines
drivers/cxl/mem.c +2 -3
        dev_dbg(dev, "Query IOCTL\n");
 
@@ -716,10 +716,10 @@ static int cxl_query_cmd(struct cxl_memdev *cxlmd,
        cxl_for_each_cmd(cmd) {
                const struct cxl_command_info *info = &cmd->info;
 
-               if (copy_to_user(&q->commands[j++], info, sizeof(*info)))
+               if (copy_to_user(&q->commands[i++], info, sizeof(*info)))
                        return -EFAULT;
 
-               if (j == n_commands)
+               if (i == n_commands)
                        break;
        }
 
--

2.13.6

#3 lore raw

PATCH v2 1/1 cxl: Make loop variable be 'i' instead of 'j'

.. otherwise people spend extra cycles looking for the inner loop and wondering 'why j'?

This was an oversight when initial work was rebased so let's fix it here.

---
v1: Initial posting
v2: Fix per Dan's request

---
 drivers/cxl/mem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cxl/mem.c +3 -3
index 244cb7d89678..d43197a193ce 100644
@@ -698,7 +698,6 @@ static int cxl_query_cmd(struct cxl_memdev *cxlmd,
 	struct device *dev = &cxlmd->dev;
 	struct cxl_mem_command *cmd;
 	u32 n_commands;
-	int j = 0;
 
 	dev_dbg(dev, "Query IOCTL\n");
 
@@ -715,11 +714,12 @@ static int cxl_query_cmd(struct cxl_memdev *cxlmd,
 	 */
 	cxl_for_each_cmd(cmd) {
 		const struct cxl_command_info *info = &cmd->info;
+		int i = 0;
 
-		if (copy_to_user(&q->commands[j++], info, sizeof(*info)))
+		if (copy_to_user(&q->commands[i++], info, sizeof(*info)))
 			return -EFAULT;
 
-		if (j == n_commands)
+		if (i == n_commands)
 			break;
 	}
 
Signature · 1 line
2.13.6
#4 lore raw

RE: [PATCH v2] cxl: Make loop variable be 'i' instead of 'j'

From: Konrad Rzeszutek Wilk

Quoted 31 lines

Sent: 26 February 2021 21:17

.. otherwise people spend extra cycles looking for the inner loop and wondering 'why j'?

This was an oversight when initial work was rebased so let's fix it here.

---
v1: Initial posting
v2: Fix per Dan's request

---
 drivers/cxl/mem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/cxl/mem.c +0 -1
index 244cb7d89678..d43197a193ce 100644
@@ -698,7 +698,6 @@ static int cxl_query_cmd(struct cxl_memdev *cxlmd,
 	struct device *dev = &cxlmd->dev;
 	struct cxl_mem_command *cmd;
 	u32 n_commands;
-	int j = 0;
 
 	dev_dbg(dev, "Query IOCTL\n");
 
@@ -715,11 +714,12 @@ static int cxl_query_cmd(struct cxl_memdev *cxlmd,
 	 */
 	cxl_for_each_cmd(cmd) {

drivers/cxl/mem.c static int cxl_query_cmd(struct cxl_memdev *cxlmd, · line 723

Quoted 10 lines
drivers/cxl/mem.c +3 -2
 		const struct cxl_command_info *info = &cmd->info;
+		int i = 0;
 
-		if (copy_to_user(&q->commands[j++], info, sizeof(*info)))
+		if (copy_to_user(&q->commands[i++], info, sizeof(*info)))
 			return -EFAULT;
 
-		if (j == n_commands)
+		if (i == n_commands)
 			break;

Did you test this?
Looks badly broken to me.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#5 lore raw

Re: [PATCH v2] cxl: Make loop variable be 'i' instead of 'j'

..snip..

Quoted 8 lines
Quoted 8 lines
drivers/cxl/mem.c +2 -1
 	cxl_for_each_cmd(cmd) {
 		const struct cxl_command_info *info = &cmd->info;
+		int i = 0;
 
-		if (copy_to_user(&q->commands[j++], info, sizeof(*info)))
+		if (copy_to_user(&q->commands[i++], info, sizeof(*info)))
 			return -EFAULT;
Quoted 7 lines

drivers/cxl/mem.c static int cxl_query_cmd(struct cxl_memdev *cxlmd, · line 723

Quoted 3 lines
drivers/cxl/mem.c +1 -1
-		if (j == n_commands)
+		if (i == n_commands)
 			break;

Did you test this?
Looks badly broken to me.

I sent out the v3 which had that fixed. See
https://lore.kernel.org/linux-cxl/[email protected]/T/#u

#6 lore raw

PATCH v3 1/1 cxl: Make loop variable be 'i' instead of 'j'

In reply to Dan Williams

.. otherwise people spend extra cycles looking for the inner loop and wondering 'why j'?

This was an oversight when initial work was rebased so let's fix it here.

---
v1: Initial posting
v2: Fix per Dan's request
v3: Duh, don't initialize i in the loop, but do it outside of it.

---
 drivers/cxl/mem.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/cxl/mem.c +4 -3
index 244cb7d89678..e7246e585e62 100644
@@ -698,7 +698,7 @@ static int cxl_query_cmd(struct cxl_memdev *cxlmd,
 	struct device *dev = &cxlmd->dev;
 	struct cxl_mem_command *cmd;
 	u32 n_commands;
-	int j = 0;
+	int i;
 
 	dev_dbg(dev, "Query IOCTL\n");
 
@@ -713,13 +713,14 @@ static int cxl_query_cmd(struct cxl_memdev *cxlmd,
 	 * otherwise, return max(n_commands, total commands) cxl_command_info
 	 * structures.
 	 */
+	i = 0;
 	cxl_for_each_cmd(cmd) {
 		const struct cxl_command_info *info = &cmd->info;
 
-		if (copy_to_user(&q->commands[j++], info, sizeof(*info)))
+		if (copy_to_user(&q->commands[i++], info, sizeof(*info)))
 			return -EFAULT;
 
-		if (j == n_commands)
+		if (i == n_commands)
 			break;
 	}
 
Signature · 1 line
2.29.2
#7 lore raw

Re: [PATCH] cxl: Make loop variable be 'i' instead of 'j'

In reply to Konrad Rzeszutek Wilk
Quoted 7 lines · Konrad Rzeszutek Wilk

.. otherwise people spend extra cycles looking for the inner loop and wondering 'why j'?

This was an over-sight when initial work was rebased so lets fix it here.

Fixes 583fa5e71cae ("cxl/mem: Add basic IOCTL interface")

^^^^^

34 days too early; otherwise, that's a damn good contender...