Skip to contentSkip to conversation

tpm_crb: Remove dead code from crb_map_res()

PATCH In review Jarkko Sakkinen 2 participants 5 messages Oct 10 – Oct 12

Subsystems (2)
lore
Share & tools
lore

Jarkko Sakkinen

author maintainer
#0 lore raw

PATCH v2 1/1 tpm_crb: Remove dead code from crb_map_res()

In all the pre-existing call sites both @iomem and @iobase_ptr are either both NULL or have a valid address.

Add an invariant for the expeced conditions and remove a dead basic block. The second block is dead given that if @iomem turns out not to be NULL, neither can't be @iobase_ptr.

---
v2:
- Updated the commit message in order to clarify things better.
- Updated the invariant in order to address checkpatch.pl --strict errors.

 drivers/char/tpm/tpm_crb.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm_crb.c +3 -6
index ceb4100ba400..833226966fa2 100644
@@ -570,15 +570,12 @@ static void __iomem *crb_map_res(struct device *dev, struct resource *iores,
 	if (start != new_res.start)
 		return IOMEM_ERR_PTR(-EINVAL);
 
+	if (!iores != !iobase_ptr)
+		return IOMEM_ERR_PTR(-EINVAL);
+
 	if (!iores)
 		return devm_ioremap_resource(dev, &new_res);
 
-	if (!*iobase_ptr) {
-		*iobase_ptr = devm_ioremap_resource(dev, iores);
-		if (IS_ERR(*iobase_ptr))
-			return *iobase_ptr;
-	}
-
 	return *iobase_ptr + (new_res.start - iores->start);
 }
 

--
2.47.3

#1 lore raw
Quoted 1 line · Jarkko Sakkinen

In all the pre-existing call sites both @iomem and @iobase_ptr are either

Do you mean @iores ?

Quoted 20 lines

both NULL or have a valid address.

Add an invariant for the expeced conditions and remove a dead basic block. The second block is dead given that if @iomem turns out not to be NULL, neither can't be @iobase_ptr.

---
v2:
- Updated the commit message in order to clarify things better.
- Updated the invariant in order to address checkpatch.pl --strict errors.

 drivers/char/tpm/tpm_crb.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm_crb.c +0 -0
index ceb4100ba400..833226966fa2 100644

drivers/char/tpm/tpm_crb.c static void __iomem *crb_map_res(struct device *dev, struct resource *iores, · line 576

Quoted 10 lines
drivers/char/tpm/tpm_crb.c +3 -1
@@ -570,15 +570,12 @@ static void __iomem *crb_map_res(struct device *dev, struct resource *iores,
 	if (start != new_res.start)
 		return IOMEM_ERR_PTR(-EINVAL);
 
+	if (!iores != !iobase_ptr)
+		return IOMEM_ERR_PTR(-EINVAL);
+
 	if (!iores)
 		return devm_ioremap_resource(dev, &new_res);
 
-	if (!*iobase_ptr) {

Sorry to insist, but in the commit description we talk about @iobase_ptr can't be null, and I agree, but here we were checking the value of the pointer, so IMO this code was not dead.

But again, I know nothing on this code. So, if you think it's correct go head, I'm surely missing something.

Thanks,
Stefano

Quoted 11 lines
drivers/char/tpm/tpm_crb.c +0 -6
-		*iobase_ptr = devm_ioremap_resource(dev, iores);
-		if (IS_ERR(*iobase_ptr))
-			return *iobase_ptr;
-	}
-
 	return *iobase_ptr + (new_res.start - iores->start);
 }
 
--

2.47.3

author maintainer
#2 lore raw
Quoted 34 lines · Stefano Garzarella
Quoted 1 line · Jarkko Sakkinen

In all the pre-existing call sites both @iomem and @iobase_ptr are either

Do you mean @iores ?

Quoted 29 lines

both NULL or have a valid address.

Add an invariant for the expeced conditions and remove a dead basic block. The second block is dead given that if @iomem turns out not to be NULL, neither can't be @iobase_ptr.

---
v2:
- Updated the commit message in order to clarify things better.
- Updated the invariant in order to address checkpatch.pl --strict errors.

 drivers/char/tpm/tpm_crb.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm_crb.c +3 -0
index ceb4100ba400..833226966fa2 100644
@@ -570,15 +570,12 @@ static void __iomem *crb_map_res(struct device *dev, struct resource *iores,
 	if (start != new_res.start)
 		return IOMEM_ERR_PTR(-EINVAL);
 
+	if (!iores != !iobase_ptr)
+		return IOMEM_ERR_PTR(-EINVAL);
+
 	if (!iores)
 		return devm_ioremap_resource(dev, &new_res);
 
Quoted 8 lines

drivers/char/tpm/tpm_crb.c static void __iomem *crb_map_res(struct device *dev, struct resource *iores, · line 576

Quoted 1 line
drivers/char/tpm/tpm_crb.c +0 -1
-	if (!*iobase_ptr) {

Sorry to insist, but in the commit description we talk about @iobase_ptr can't be null, and I agree, but here we were checking the value of the pointer, so IMO this code was not dead.

But again, I know nothing on this code. So, if you think it's correct go head, I'm surely missing something.

Ugh, you're actually right, and this is not, and should not have sent this. And it is for lazy init.

I need to sanity check my test environment because I thought I was testing this with swtpm emulated tpm_crb but tests passed, and this should not work.

Sorry and thanks :-)

Just wanted to make it explicit that I was making somehting extremely stupid.

Quoted 12 lines

Thanks,
Stefano

Quoted 8 lines
drivers/char/tpm/tpm_crb.c +0 -5
-		*iobase_ptr = devm_ioremap_resource(dev, iores);
-		if (IS_ERR(*iobase_ptr))
-			return *iobase_ptr;
-	}
-
 	return *iobase_ptr + (new_res.start - iores->start);
 }
 
Quoted 4 lines
Quoted 3 lines

--
2.47.3

Br, Jarkko

author maintainer
#3 lore raw
Quoted 47 lines · Jarkko Sakkinen
Quoted 34 lines · Stefano Garzarella
Quoted 1 line · Jarkko Sakkinen

In all the pre-existing call sites both @iomem and @iobase_ptr are either

Do you mean @iores ?

Quoted 29 lines

both NULL or have a valid address.

Add an invariant for the expeced conditions and remove a dead basic block. The second block is dead given that if @iomem turns out not to be NULL, neither can't be @iobase_ptr.

---
v2:
- Updated the commit message in order to clarify things better.
- Updated the invariant in order to address checkpatch.pl --strict errors.

 drivers/char/tpm/tpm_crb.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm_crb.c +3 -0
index ceb4100ba400..833226966fa2 100644
@@ -570,15 +570,12 @@ static void __iomem *crb_map_res(struct device *dev, struct resource *iores,
 	if (start != new_res.start)
 		return IOMEM_ERR_PTR(-EINVAL);
 
+	if (!iores != !iobase_ptr)
+		return IOMEM_ERR_PTR(-EINVAL);
+
 	if (!iores)
 		return devm_ioremap_resource(dev, &new_res);
 
Quoted 8 lines

drivers/char/tpm/tpm_crb.c static void __iomem *crb_map_res(struct device *dev, struct resource *iores, · line 576

Quoted 1 line
drivers/char/tpm/tpm_crb.c +0 -1
-	if (!*iobase_ptr) {

Sorry to insist, but in the commit description we talk about @iobase_ptr can't be null, and I agree, but here we were checking the value of the pointer, so IMO this code was not dead.

But again, I know nothing on this code. So, if you think it's correct go head, I'm surely missing something.

Ugh, you're actually right, and this is not, and should not have sent this. And it is for lazy init.

Quoted 8 lines

I need to sanity check my test environment because I thought I was testing this with swtpm emulated tpm_crb but tests passed, and this should not work.

Sorry and thanks :-)

Just wanted to make it explicit that I was making somehting extremely stupid.

Probably too much multitasking lately with all these bugs.

Lessons learned is that from now on I keep my own contributions and reviewing in separate sessions. Things have gotten much busier than they used to be so need to adapt and learn how to have focus on all actitivies :-)

Br, Jarkko

#4 lore raw
Quoted 42 lines · Jarkko Sakkinen
Quoted 41 lines · Jarkko Sakkinen
Quoted 40 lines · Stefano Garzarella
Quoted 1 line · Jarkko Sakkinen

In all the pre-existing call sites both @iomem and @iobase_ptr are either

Do you mean @iores ?

Quoted 20 lines

both NULL or have a valid address.

Add an invariant for the expeced conditions and remove a dead basic block. The second block is dead given that if @iomem turns out not to be NULL, neither can't be @iobase_ptr.

---
v2:
- Updated the commit message in order to clarify things better.
- Updated the invariant in order to address checkpatch.pl --strict errors.

 drivers/char/tpm/tpm_crb.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm_crb.c +0 -0
index ceb4100ba400..833226966fa2 100644

drivers/char/tpm/tpm_crb.c static void __iomem *crb_map_res(struct device *dev, struct resource *iores, · line 576

Quoted 10 lines
drivers/char/tpm/tpm_crb.c +3 -1
@@ -570,15 +570,12 @@ static void __iomem *crb_map_res(struct device *dev, struct resource *iores,
 	if (start != new_res.start)
 		return IOMEM_ERR_PTR(-EINVAL);
 
+	if (!iores != !iobase_ptr)
+		return IOMEM_ERR_PTR(-EINVAL);
+
 	if (!iores)
 		return devm_ioremap_resource(dev, &new_res);
 
-	if (!*iobase_ptr) {

Sorry to insist, but in the commit description we talk about @iobase_ptr can't be null, and I agree, but here we were checking the value of the pointer, so IMO this code was not dead.

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

But again, I know nothing on this code. So, if you think it's correct go head, I'm surely missing something.

Ugh, you're actually right, and this is not, and should not have sent this. And it is for lazy init.

Yeah, a lazy init makes sense.

Quoted 6 lines
Quoted 6 lines

I need to sanity check my test environment because I thought I was testing this with swtpm emulated tpm_crb but tests passed, and this should not work.

Sorry and thanks :-)

You're welcome!

Quoted 3 lines
Quoted 3 lines

Just wanted to make it explicit that I was making somehting extremely stupid.

Don't beat yourself up, it happens to all of us! Thanks for taking the time to check and clarify!

Quoted 7 lines

Probably too much multitasking lately with all these bugs.

Lessons learned is that from now on I keep my own contributions and reviewing in separate sessions. Things have gotten much busier than they used to be so need to adapt and learn how to have focus on all actitivies :-)

Yeah, it's something that's happening here too, and it's a real pain to deal with! :-(

Thanks,
Stefano