All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] tpm_crb: Remove dead code from crb_map_res()
@ 2026-10-10 23:54 Jarkko Sakkinen
  2026-10-12 10:23 ` Stefano Garzarella
  0 siblings, 1 reply; 5+ messages in thread
From: Jarkko Sakkinen @ 2026-10-10 23:54 UTC (permalink / raw)
  To: linux-integrity
  Cc: Stefano Garzarella, Jarkko Sakkinen, Peter Huewe, Jason Gunthorpe,
	Stuart Yoder, Rafael J. Wysocki, Chu Guangqing, linux-kernel

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.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
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(-)

diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
index ceb4100ba400..833226966fa2 100644
--- a/drivers/char/tpm/tpm_crb.c
+++ b/drivers/char/tpm/tpm_crb.c
@@ -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


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

* Re: [PATCH v2] tpm_crb: Remove dead code from crb_map_res()
  2026-10-10 23:54 [PATCH v2] tpm_crb: Remove dead code from crb_map_res() Jarkko Sakkinen
@ 2026-10-12 10:23 ` Stefano Garzarella
  2026-10-12 13:31   ` Jarkko Sakkinen
  0 siblings, 1 reply; 5+ messages in thread
From: Stefano Garzarella @ 2026-10-12 10:23 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: linux-integrity, Peter Huewe, Jason Gunthorpe, Stuart Yoder,
	Rafael J. Wysocki, Chu Guangqing, linux-kernel

On Sun, Oct 11, 2026 at 02:54:57AM +0300, Jarkko Sakkinen wrote:
> In all the pre-existing call sites both @iomem and @iobase_ptr are either

Do you mean @iores ?

> 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.
> 
> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
> ---
> 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(-)
> 
> diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
> index ceb4100ba400..833226966fa2 100644
> --- a/drivers/char/tpm/tpm_crb.c
> +++ b/drivers/char/tpm/tpm_crb.c
> @@ -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

> -		*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
> 


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

* Re: [PATCH v2] tpm_crb: Remove dead code from crb_map_res()
  2026-10-12 10:23 ` Stefano Garzarella
@ 2026-10-12 13:31   ` Jarkko Sakkinen
  2026-10-12 13:53     ` Jarkko Sakkinen
  0 siblings, 1 reply; 5+ messages in thread
From: Jarkko Sakkinen @ 2026-10-12 13:31 UTC (permalink / raw)
  To: Stefano Garzarella
  Cc: linux-integrity, Peter Huewe, Jason Gunthorpe, Stuart Yoder,
	Rafael J. Wysocki, Chu Guangqing, linux-kernel

On Mon, Oct 12, 2026 at 12:23:05PM +0200, Stefano Garzarella wrote:
> On Sun, Oct 11, 2026 at 02:54:57AM +0300, Jarkko Sakkinen wrote:
> > In all the pre-existing call sites both @iomem and @iobase_ptr are either
> 
> Do you mean @iores ?
> 
> > 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.
> > 
> > Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
> > ---
> > 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(-)
> > 
> > diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
> > index ceb4100ba400..833226966fa2 100644
> > --- a/drivers/char/tpm/tpm_crb.c
> > +++ b/drivers/char/tpm/tpm_crb.c
> > @@ -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.

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.

> 
> Thanks,
> Stefano
> 
> > -		*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
> > 
> 

Br, Jarkko

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

* Re: [PATCH v2] tpm_crb: Remove dead code from crb_map_res()
  2026-10-12 13:31   ` Jarkko Sakkinen
@ 2026-10-12 13:53     ` Jarkko Sakkinen
  2026-10-12 14:16       ` Stefano Garzarella
  0 siblings, 1 reply; 5+ messages in thread
From: Jarkko Sakkinen @ 2026-10-12 13:53 UTC (permalink / raw)
  To: Stefano Garzarella
  Cc: linux-integrity, Peter Huewe, Jason Gunthorpe, Stuart Yoder,
	Rafael J. Wysocki, Chu Guangqing, linux-kernel

On Mon, Oct 12, 2026 at 04:31:45PM +0300, Jarkko Sakkinen wrote:
> On Mon, Oct 12, 2026 at 12:23:05PM +0200, Stefano Garzarella wrote:
> > On Sun, Oct 11, 2026 at 02:54:57AM +0300, Jarkko Sakkinen wrote:
> > > In all the pre-existing call sites both @iomem and @iobase_ptr are either
> > 
> > Do you mean @iores ?
> > 
> > > 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.
> > > 
> > > Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
> > > ---
> > > 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(-)
> > > 
> > > diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
> > > index ceb4100ba400..833226966fa2 100644
> > > --- a/drivers/char/tpm/tpm_crb.c
> > > +++ b/drivers/char/tpm/tpm_crb.c
> > > @@ -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.
> 
> 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.

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

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

* Re: [PATCH v2] tpm_crb: Remove dead code from crb_map_res()
  2026-10-12 13:53     ` Jarkko Sakkinen
@ 2026-10-12 14:16       ` Stefano Garzarella
  0 siblings, 0 replies; 5+ messages in thread
From: Stefano Garzarella @ 2026-10-12 14:16 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: linux-integrity, Peter Huewe, Jason Gunthorpe, Stuart Yoder,
	Rafael J. Wysocki, Chu Guangqing, linux-kernel

On Mon, Oct 12, 2026 at 04:53:52PM +0300, Jarkko Sakkinen wrote:
>On Mon, Oct 12, 2026 at 04:31:45PM +0300, Jarkko Sakkinen wrote:
>> On Mon, Oct 12, 2026 at 12:23:05PM +0200, Stefano Garzarella wrote:
>> > On Sun, Oct 11, 2026 at 02:54:57AM +0300, Jarkko Sakkinen wrote:
>> > > In all the pre-existing call sites both @iomem and @iobase_ptr are either
>> >
>> > Do you mean @iores ?
>> >
>> > > 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.
>> > >
>> > > Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
>> > > ---
>> > > 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(-)
>> > >
>> > > diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
>> > > index ceb4100ba400..833226966fa2 100644
>> > > --- a/drivers/char/tpm/tpm_crb.c
>> > > +++ b/drivers/char/tpm/tpm_crb.c
>> > > @@ -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.
>>
>> 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.

>>
>> 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!

>>
>> 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!

>
>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


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

end of thread, other threads:[~2026-10-12 14:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-10 23:54 [PATCH v2] tpm_crb: Remove dead code from crb_map_res() Jarkko Sakkinen
2026-10-12 10:23 ` Stefano Garzarella
2026-10-12 13:31   ` Jarkko Sakkinen
2026-10-12 13:53     ` Jarkko Sakkinen
2026-10-12 14:16       ` Stefano Garzarella

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.