Skip to contentSkip to conversation

cpu: remove some dead code in store_cache_disable()

PATCH In review Dan Carpenter 5 participants 10 messages Apr 19, 2012 – Apr 25, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpu: remove some dead code in store_cache_disable()

amd_set_l3_disable_slot() never returns -EEXIST, it only returns -EINVAL or zero.

arch/x86/kernel/cpu/intel_cacheinfo.c +2 -5
index 73d08ed..7b4e294 100644
@@ -466,12 +466,9 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
 		return -EINVAL;
 
 	err = amd_set_l3_disable_slot(this_leaf->base.nb, cpu, slot, val);
-	if (err) {
-		if (err = -EEXIST)
-			printk(KERN_WARNING "L3 disable slot %d in use!\n",
-					    slot);
+	if (err)
 		return err;
-	}
+
 	return count;
 }
 
#1 lore raw
Quoted 14 lines · Dan Carpenter

amd_set_l3_disable_slot() never returns -EEXIST, it only returns -EINVAL or zero.

arch/x86/kernel/cpu/intel_cacheinfo.c +0 -1
index 73d08ed..7b4e294 100644
@@ -466,12 +466,9 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
 		return -EINVAL;
 
 	err = amd_set_l3_disable_slot(this_leaf->base.nb, cpu, slot, val);
-	if (err) {

arch/x86/kernel/cpu/intel_cacheinfo.c static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf, · line 474

Quoted 10 lines
arch/x86/kernel/cpu/intel_cacheinfo.c +2 -4
-		if (err = -EEXIST)
-			printk(KERN_WARNING "L3 disable slot %d in use!\n",
-					    slot);
+	if (err)
 		return err;
-	}
+
 	return count;
 }
 

Looking at the comments around the code and the print statement your patch is trying to remove, I wonder if it would be more appropriate to return -EEXIST in amd_set_l3_disable_slot(), like this:

---
From: Srivatsa S. Bhat <[email protected]>
Subject: [PATCH] cpu: Fix error return code in amd_set_l3_disable_slot()

If the L3 disable slot is already in use, return -EEXIST instead of -EINVAL. The caller, store_cache_disable(), checks this return value to print an appropriate warning.

---

 arch/x86/kernel/cpu/intel_cacheinfo.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/intel_cacheinfo.c +1 -1
index 73d08ed..0b49e29 100644
@@ -433,7 +433,7 @@ int amd_set_l3_disable_slot(struct amd_northbridge *nb, int cpu, unsigned slot,
 	/*  check if @slot is already used or the index is already disabled */
 	ret = amd_get_l3_disable_slot(nb, slot);
 	if (ret >= 0)
-		return -EINVAL;
+		return -EEXIST;
 
 	if (index > nb->l3_cache.indices)
 		return -EINVAL;

Regards,
Srivatsa S. Bhat

#2 lore raw
Quoted 52 lines · Srivatsa S. Bhat
Quoted 14 lines · Dan Carpenter

amd_set_l3_disable_slot() never returns -EEXIST, it only returns -EINVAL or zero.

arch/x86/kernel/cpu/intel_cacheinfo.c +0 -1
index 73d08ed..7b4e294 100644
@@ -466,12 +466,9 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
 		return -EINVAL;
 
 	err = amd_set_l3_disable_slot(this_leaf->base.nb, cpu, slot, val);
-	if (err) {

arch/x86/kernel/cpu/intel_cacheinfo.c static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf, · line 474

Quoted 10 lines
arch/x86/kernel/cpu/intel_cacheinfo.c +2 -4
-		if (err = -EEXIST)
-			printk(KERN_WARNING "L3 disable slot %d in use!\n",
-					    slot);
+	if (err)
 		return err;
-	}
+
 	return count;
 }
 

Looking at the comments around the code and the print statement your patch is trying to remove, I wonder if it would be more appropriate to return -EEXIST in amd_set_l3_disable_slot(), like this:

---
From: Srivatsa S. Bhat <[email protected]>
Subject: [PATCH] cpu: Fix error return code in amd_set_l3_disable_slot()

If the L3 disable slot is already in use, return -EEXIST instead of -EINVAL. The caller, store_cache_disable(), checks this return value to print an appropriate warning.

---

 arch/x86/kernel/cpu/intel_cacheinfo.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/intel_cacheinfo.c +0 -0
index 73d08ed..0b49e29 100644

arch/x86/kernel/cpu/intel_cacheinfo.c int amd_set_l3_disable_slot(struct amd_northbridge *nb, int cpu, unsigned slot, · line 439

Quoted 8 lines
arch/x86/kernel/cpu/intel_cacheinfo.c +1 -1
@@ -433,7 +433,7 @@ int amd_set_l3_disable_slot(struct amd_northbridge *nb, int cpu, unsigned slot,
 	/*  check if @slot is already used or the index is already disabled */
 	ret = amd_get_l3_disable_slot(nb, slot);
 	if (ret >= 0)
-		return -EINVAL;
+		return -EEXIST;
 
 	if (index > nb->l3_cache.indices)
 		return -EINVAL;

Well, let's see, there's 8cc1176e5de534d55cb26ff0cef3fd0d6ad8c3c0 which was intending at looking at -EEXIST when it gets returned but forgot to return it at the end. Crap. Somebody should b*tchslap its author... oh, that's me.

Good catch guys, thanks. I'll take a bit enhanced version of Srivatsa's patch because it goes in the way of what was originally intended. The enhanced version returns -EEXIST for the other slot too when we're disabling the same index, see below:

--
From: "Srivatsa S. Bhat" <[email protected]>
Date: Thu, 19 Apr 2012 12:35:08 +0200
Subject: [PATCH] x86, intel_cacheinfo: Fix error return code in amd_set_l3_disable_slot()

If the L3 disable slot is already in use, return -EEXIST instead of -EINVAL. The caller, store_cache_disable(), checks this return value to print an appropriate warning.

Also, we want to signal with -EEXIST that the current index we're disabling has actually been already disabled on the node:

$ echo 12 > /sys/devices/system/cpu/cpu3/cache/index3/cache_disable_0
$ echo 12 > /sys/devices/system/cpu/cpu3/cache/index3/cache_disable_0
-bash: echo: write error: File exists
$ echo 12 > /sys/devices/system/cpu/cpu3/cache/index3/cache_disable_1
-bash: echo: write error: File exists
$ echo 12 > /sys/devices/system/cpu/cpu5/cache/index3/cache_disable_1
-bash: echo: write error: File exists

The old code would say

-bash: echo: write error: Invalid argument

for disable slot 1 when playing the example above with no output in dmesg, which is clearly misleading.

---
 arch/x86/kernel/cpu/intel_cacheinfo.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/intel_cacheinfo.c +4 -4
index 73d08ed98a64..b8f3653dddbc 100644
@@ -433,14 +433,14 @@ int amd_set_l3_disable_slot(struct amd_northbridge *nb, int cpu, unsigned slot,
 	/*  check if @slot is already used or the index is already disabled */
 	ret = amd_get_l3_disable_slot(nb, slot);
 	if (ret >= 0)
-		return -EINVAL;
+		return -EEXIST;
 
 	if (index > nb->l3_cache.indices)
 		return -EINVAL;
 
 	/* check whether the other slot has disabled the same index already */
 	if (index = amd_get_l3_disable_slot(nb, !slot))
-		return -EINVAL;
+		return -EEXIST;
 
 	amd_l3_disable_index(nb, cpu, slot, index);
 
@@ -468,8 +468,8 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
 	err = amd_set_l3_disable_slot(this_leaf->base.nb, cpu, slot, val);
 	if (err) {
 		if (err = -EEXIST)
-			printk(KERN_WARNING "L3 disable slot %d in use!\n",
-					    slot);
+			pr_warning("L3 slot %d in use/index already disabled!\n",
+				   slot);
 		return err;
 	}
 	return count;
Signature · 12 lines
1.7.9.3.362.g71319


-- 
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
#3 lore raw
Quoted 133 lines · Borislav Petkov
Quoted 52 lines · Srivatsa S. Bhat
Quoted 14 lines · Dan Carpenter

amd_set_l3_disable_slot() never returns -EEXIST, it only returns -EINVAL or zero.

arch/x86/kernel/cpu/intel_cacheinfo.c +0 -1
index 73d08ed..7b4e294 100644
@@ -466,12 +466,9 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
 		return -EINVAL;
 
 	err = amd_set_l3_disable_slot(this_leaf->base.nb, cpu, slot, val);
-	if (err) {

arch/x86/kernel/cpu/intel_cacheinfo.c static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf, · line 474

Quoted 10 lines
arch/x86/kernel/cpu/intel_cacheinfo.c +2 -4
-		if (err = -EEXIST)
-			printk(KERN_WARNING "L3 disable slot %d in use!\n",
-					    slot);
+	if (err)
 		return err;
-	}
+
 	return count;
 }
 

Looking at the comments around the code and the print statement your patch is trying to remove, I wonder if it would be more appropriate to return -EEXIST in amd_set_l3_disable_slot(), like this:

---
From: Srivatsa S. Bhat <[email protected]>
Subject: [PATCH] cpu: Fix error return code in amd_set_l3_disable_slot()

If the L3 disable slot is already in use, return -EEXIST instead of -EINVAL. The caller, store_cache_disable(), checks this return value to print an appropriate warning.

---

 arch/x86/kernel/cpu/intel_cacheinfo.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/intel_cacheinfo.c +0 -0
index 73d08ed..0b49e29 100644

arch/x86/kernel/cpu/intel_cacheinfo.c int amd_set_l3_disable_slot(struct amd_northbridge *nb, int cpu, unsigned slot, · line 439

Quoted 8 lines
arch/x86/kernel/cpu/intel_cacheinfo.c +1 -1
@@ -433,7 +433,7 @@ int amd_set_l3_disable_slot(struct amd_northbridge *nb, int cpu, unsigned slot,
 	/*  check if @slot is already used or the index is already disabled */
 	ret = amd_get_l3_disable_slot(nb, slot);
 	if (ret >= 0)
-		return -EINVAL;
+		return -EEXIST;
 
 	if (index > nb->l3_cache.indices)
 		return -EINVAL;

Well, let's see, there's 8cc1176e5de534d55cb26ff0cef3fd0d6ad8c3c0 which was intending at looking at -EEXIST when it gets returned but forgot to return it at the end. Crap. Somebody should b*tchslap its author... oh, that's me.

Good catch guys, thanks. I'll take a bit enhanced version of Srivatsa's patch because it goes in the way of what was originally intended. The enhanced version returns -EEXIST for the other slot too when we're disabling the same index, see below:

--

From: "Srivatsa S. Bhat" <[email protected]>
Date: Thu, 19 Apr 2012 12:35:08 +0200
Subject: [PATCH] x86, intel_cacheinfo: Fix error return code in amd_set_l3_disable_slot()

If the L3 disable slot is already in use, return -EEXIST instead of -EINVAL. The caller, store_cache_disable(), checks this return value to print an appropriate warning.

Also, we want to signal with -EEXIST that the current index we're disabling has actually been already disabled on the node:

$ echo 12 > /sys/devices/system/cpu/cpu3/cache/index3/cache_disable_0
$ echo 12 > /sys/devices/system/cpu/cpu3/cache/index3/cache_disable_0
-bash: echo: write error: File exists
$ echo 12 > /sys/devices/system/cpu/cpu3/cache/index3/cache_disable_1
-bash: echo: write error: File exists
$ echo 12 > /sys/devices/system/cpu/cpu5/cache/index3/cache_disable_1
-bash: echo: write error: File exists

The old code would say

-bash: echo: write error: Invalid argument

for disable slot 1 when playing the example above with no output in dmesg, which is clearly misleading.

---
 arch/x86/kernel/cpu/intel_cacheinfo.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/intel_cacheinfo.c +2 -2
index 73d08ed98a64..b8f3653dddbc 100644
@@ -433,14 +433,14 @@ int amd_set_l3_disable_slot(struct amd_northbridge *nb, int cpu, unsigned slot,
 	/*  check if @slot is already used or the index is already disabled */
 	ret = amd_get_l3_disable_slot(nb, slot);
 	if (ret >= 0)
-		return -EINVAL;
+		return -EEXIST;
 
 	if (index > nb->l3_cache.indices)
 		return -EINVAL;
 
 	/* check whether the other slot has disabled the same index already */
 	if (index = amd_get_l3_disable_slot(nb, !slot))
-		return -EINVAL;
+		return -EEXIST;
 
 	amd_l3_disable_index(nb, cpu, slot, index);
 

arch/x86/kernel/cpu/intel_cacheinfo.c static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf, · line 475

Quoted 10 lines
arch/x86/kernel/cpu/intel_cacheinfo.c +2 -2
@@ -468,8 +468,8 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
 	err = amd_set_l3_disable_slot(this_leaf->base.nb, cpu, slot, val);
 	if (err) {
 		if (err = -EEXIST)
-			printk(KERN_WARNING "L3 disable slot %d in use!\n",
-					    slot);
+			pr_warning("L3 slot %d in use/index already disabled!\n",
+				   slot);
 		return err;
 	}
 	return count;

Wow, that's even better! Thanks :-)

Regards,
Srivatsa S. Bhat

#5 lore raw

[GIT PULL] L3 CID fix for 3.5

Hi guys,

please pull the following fix for L3 cache index disable into tip. Since there's no real breakage but simply a correctness issue, it can wait for 3.5. I've also removed the stable tag I had in the previous version.

Thanks.

--
The following changes since commit e816b57a337ea3b755de72bec38c10c864f23015:

Linux 3.4-rc3 (2012-04-15 18:28:29 -0700)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/bp/bp.git tags/l3-fix-for-3.5

for you to fetch changes up to a720b2dd2470a52345df11dca8d6c1466599f812:

x86, intel_cacheinfo: Fix error return code in amd_set_l3_disable_slot() (2012-04-19 18:30:28 +0200)

----------------------------------------------------------------
A small L3 cache index disable fix from Srivatsa Bhat which unifies the way the code checks for already disabled indices.

----------------------------------------------------------------
Srivatsa S. Bhat (1):
x86, intel_cacheinfo: Fix error return code in amd_set_l3_disable_slot()

 arch/x86/kernel/cpu/intel_cacheinfo.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Appending patch here too:

--
commit a720b2dd2470a52345df11dca8d6c1466599f812

Author: Srivatsa S. Bhat <[email protected]>
Date:   Thu Apr 19 12:35:08 2012 +0200

x86, intel_cacheinfo: Fix error return code in amd_set_l3_disable_slot()

If the L3 disable slot is already in use, return -EEXIST instead of -EINVAL. The caller, store_cache_disable(), checks this return value to print an appropriate warning.

Also, we want to signal with -EEXIST that the current index we're disabling has actually been already disabled on the node:

$ echo 12 > /sys/devices/system/cpu/cpu3/cache/index3/cache_disable_0 $ echo 12 > /sys/devices/system/cpu/cpu3/cache/index3/cache_disable_0 -bash: echo: write error: File exists
$ echo 12 > /sys/devices/system/cpu/cpu3/cache/index3/cache_disable_1 -bash: echo: write error: File exists
$ echo 12 > /sys/devices/system/cpu/cpu5/cache/index3/cache_disable_1 -bash: echo: write error: File exists

The old code would say

-bash: echo: write error: Invalid argument

for disable slot 1 when playing the example above with no output in dmesg, which is clearly misleading.

arch/x86/kernel/cpu/intel_cacheinfo.c +4 -4
index 73d08ed98a64..b8f3653dddbc 100644
@@ -433,14 +433,14 @@ int amd_set_l3_disable_slot(struct amd_northbridge *nb, int cpu, unsigned slot,
 	/*  check if @slot is already used or the index is already disabled */
 	ret = amd_get_l3_disable_slot(nb, slot);
 	if (ret >= 0)
-		return -EINVAL;
+		return -EEXIST;
 
 	if (index > nb->l3_cache.indices)
 		return -EINVAL;
 
 	/* check whether the other slot has disabled the same index already */
 	if (index = amd_get_l3_disable_slot(nb, !slot))
-		return -EINVAL;
+		return -EEXIST;
 
 	amd_l3_disable_index(nb, cpu, slot, index);
 
@@ -468,8 +468,8 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
 	err = amd_set_l3_disable_slot(this_leaf->base.nb, cpu, slot, val);
 	if (err) {
 		if (err = -EEXIST)
-			printk(KERN_WARNING "L3 disable slot %d in use!\n",
-					    slot);
+			pr_warning("L3 slot %d in use/index already disabled!\n",
+				   slot);
 		return err;
 	}
 	return count;
Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
#6 lore raw

Re: [GIT PULL] L3 CID fix for 3.5

Ping?

Guys, any issues with this that I should know of?

Thanks.

Quoted 115 lines · Borislav Petkov

Hi guys,

please pull the following fix for L3 cache index disable into tip. Since there's no real breakage but simply a correctness issue, it can wait for 3.5. I've also removed the stable tag I had in the previous version.

Thanks.

--
The following changes since commit e816b57a337ea3b755de72bec38c10c864f23015:

Linux 3.4-rc3 (2012-04-15 18:28:29 -0700)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/bp/bp.git tags/l3-fix-for-3.5

for you to fetch changes up to a720b2dd2470a52345df11dca8d6c1466599f812:

x86, intel_cacheinfo: Fix error return code in amd_set_l3_disable_slot() (2012-04-19 18:30:28 +0200)

----------------------------------------------------------------
A small L3 cache index disable fix from Srivatsa Bhat which unifies the way the code checks for already disabled indices.

----------------------------------------------------------------
Srivatsa S. Bhat (1):
x86, intel_cacheinfo: Fix error return code in amd_set_l3_disable_slot()

 arch/x86/kernel/cpu/intel_cacheinfo.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Appending patch here too:

--
commit a720b2dd2470a52345df11dca8d6c1466599f812

Author: Srivatsa S. Bhat <[email protected]>
Date:   Thu Apr 19 12:35:08 2012 +0200

x86, intel_cacheinfo: Fix error return code in amd_set_l3_disable_slot()

If the L3 disable slot is already in use, return -EEXIST instead of -EINVAL. The caller, store_cache_disable(), checks this return value to print an appropriate warning.

Also, we want to signal with -EEXIST that the current index we're disabling has actually been already disabled on the node:

$ echo 12 > /sys/devices/system/cpu/cpu3/cache/index3/cache_disable_0 $ echo 12 > /sys/devices/system/cpu/cpu3/cache/index3/cache_disable_0 -bash: echo: write error: File exists
$ echo 12 > /sys/devices/system/cpu/cpu3/cache/index3/cache_disable_1 -bash: echo: write error: File exists
$ echo 12 > /sys/devices/system/cpu/cpu5/cache/index3/cache_disable_1 -bash: echo: write error: File exists

The old code would say

-bash: echo: write error: Invalid argument

for disable slot 1 when playing the example above with no output in dmesg, which is clearly misleading.

arch/x86/kernel/cpu/intel_cacheinfo.c +4 -4
index 73d08ed98a64..b8f3653dddbc 100644
@@ -433,14 +433,14 @@ int amd_set_l3_disable_slot(struct amd_northbridge *nb, int cpu, unsigned slot,
 	/*  check if @slot is already used or the index is already disabled */
 	ret = amd_get_l3_disable_slot(nb, slot);
 	if (ret >= 0)
-		return -EINVAL;
+		return -EEXIST;
 
 	if (index > nb->l3_cache.indices)
 		return -EINVAL;
 
 	/* check whether the other slot has disabled the same index already */
 	if (index = amd_get_l3_disable_slot(nb, !slot))
-		return -EINVAL;
+		return -EEXIST;
 
 	amd_l3_disable_index(nb, cpu, slot, index);
 
@@ -468,8 +468,8 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
 	err = amd_set_l3_disable_slot(this_leaf->base.nb, cpu, slot, val);
 	if (err) {
 		if (err = -EEXIST)
-			printk(KERN_WARNING "L3 disable slot %d in use!\n",
-					    slot);
+			pr_warning("L3 slot %d in use/index already disabled!\n",
+				   slot);
 		return err;
 	}
 	return count;
Signature · 13 lines
-- 
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
_______________________________________________
osrc-patches mailing list
[email protected]
https://elbe.amd.com/mailman/listinfo/osrc-patches
Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
#7 lore raw

Re: [GIT PULL] L3 CID fix for 3.5

Quoted 3 lines · Borislav Petkov

Ping?

Guys, any issues with this that I should know of?

Looks good to me. You marked it v3.5, should I pull it into v3.4? Looks small enough to me and we better keep such user facing interfaces correct, even if there's no direct regression.

Thanks,

Ingo

#8 lore raw

Re: [GIT PULL] L3 CID fix for 3.5

Quoted 3 lines · Ingo Molnar

Looks good to me. You marked it v3.5, should I pull it into v3.4? Looks small enough to me and we better keep such user facing interfaces correct, even if there's no direct regression.

I'm fine with whatever you decide,

thanks.

Signature · 8 lines
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
#9 lore raw

[tip:x86/urgent] x86, intel_cacheinfo: Fix error return code in amd_set_l3_disable_slot()

In reply to Dan Carpenter
Commit-ID:  a720b2dd2470a52345df11dca8d6c1466599f812
Gitweb:     http://git.kernel.org/tip/a720b2dd2470a52345df11dca8d6c1466599f812
Author:     Srivatsa S. Bhat <[email protected]>
AuthorDate: Thu, 19 Apr 2012 12:35:08 +0200
Committer:  Borislav Petkov <[email protected]>
CommitDate: Thu, 19 Apr 2012 18:30:28 +0200

x86, intel_cacheinfo: Fix error return code in amd_set_l3_disable_slot()

If the L3 disable slot is already in use, return -EEXIST instead of -EINVAL. The caller, store_cache_disable(), checks this return value to print an appropriate warning.

Also, we want to signal with -EEXIST that the current index we're disabling has actually been already disabled on the node:

$ echo 12 > /sys/devices/system/cpu/cpu3/cache/index3/cache_disable_0
$ echo 12 > /sys/devices/system/cpu/cpu3/cache/index3/cache_disable_0
-bash: echo: write error: File exists
$ echo 12 > /sys/devices/system/cpu/cpu3/cache/index3/cache_disable_1
-bash: echo: write error: File exists
$ echo 12 > /sys/devices/system/cpu/cpu5/cache/index3/cache_disable_1
-bash: echo: write error: File exists

The old code would say

-bash: echo: write error: Invalid argument

for disable slot 1 when playing the example above with no output in dmesg, which is clearly misleading.

---
 arch/x86/kernel/cpu/intel_cacheinfo.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/intel_cacheinfo.c +4 -4
index 73d08ed..b8f3653 100644
@@ -433,14 +433,14 @@ int amd_set_l3_disable_slot(struct amd_northbridge *nb, int cpu, unsigned slot,
 	/*  check if @slot is already used or the index is already disabled */
 	ret = amd_get_l3_disable_slot(nb, slot);
 	if (ret >= 0)
-		return -EINVAL;
+		return -EEXIST;
 
 	if (index > nb->l3_cache.indices)
 		return -EINVAL;
 
 	/* check whether the other slot has disabled the same index already */
 	if (index == amd_get_l3_disable_slot(nb, !slot))
-		return -EINVAL;
+		return -EEXIST;
 
 	amd_l3_disable_index(nb, cpu, slot, index);
 
@@ -468,8 +468,8 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
 	err = amd_set_l3_disable_slot(this_leaf->base.nb, cpu, slot, val);
 	if (err) {
 		if (err == -EEXIST)
-			printk(KERN_WARNING "L3 disable slot %d in use!\n",
-					    slot);
+			pr_warning("L3 slot %d in use/index already disabled!\n",
+				   slot);
 		return err;
 	}
 	return count;