Skip to contentSkip to conversation

usb: gadget: udc: bdc: Remove unnecessary NULL checks in bdc_req_complete

PATCH Superseded Nathan Chancellor 4 participants 11 messages Oct 23, 2019 – Mar 30, 2020

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

PATCH 1/1 usb: gadget: udc: bdc: Remove unnecessary NULL checks in bdc_req_complete

When building with Clang + -Wtautological-pointer-compare:

drivers/usb/gadget/udc/bdc/bdc_ep.c:543:28: warning: comparison of address of 'req->queue' equal to a null pointer is always false [-Wtautological-pointer-compare]

        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                             ~~~~~^~~~~    ~~~~
drivers/usb/gadget/udc/bdc/bdc_ep.c:543:51: warning: comparison of
address of 'req->usb_req' equal to a null pointer is always false
[-Wtautological-pointer-compare]
        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                                                    ~~~~~^~~~~~~    ~~~~

2 warnings generated.

As it notes, these statements will always evaluate to false so remove them.

Fixes efed421a94e6 ("usb: gadget: Add UDC driver for Broadcom USB3.0 device controller IP BDC")

---

Note: I am not sure if these checks were intended to check if the contents of these arrays were NULL or if there should be some other checks in lieu of these; I am not familiar with the USB subsystem to answer this but I will happily respin the patch if this is not correct.

 drivers/usb/gadget/udc/bdc/bdc_ep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/udc/bdc/bdc_ep.c +1 -1
index a4d9b5e1e50e..d49c6dc1082d 100644
@@ -540,7 +540,7 @@ static void bdc_req_complete(struct bdc_ep *ep, struct bdc_req *req,
 {
 	struct bdc *bdc = ep->bdc;
 
-	if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
+	if (req == NULL)
 		return;
 
 	dev_dbg(bdc->dev, "%s ep:%s status:%d\n", __func__, ep->name, status);
Signature · 1 line
2.23.0
#1 lore raw

I know it has been a while but ping?

Quoted 46 lines · Nathan Chancellor

When building with Clang + -Wtautological-pointer-compare:

drivers/usb/gadget/udc/bdc/bdc_ep.c:543:28: warning: comparison of address of 'req->queue' equal to a null pointer is always false [-Wtautological-pointer-compare]

        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                             ~~~~~^~~~~    ~~~~
drivers/usb/gadget/udc/bdc/bdc_ep.c:543:51: warning: comparison of
address of 'req->usb_req' equal to a null pointer is always false
[-Wtautological-pointer-compare]
        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                                                    ~~~~~^~~~~~~    ~~~~

2 warnings generated.

As it notes, these statements will always evaluate to false so remove them.

Fixes efed421a94e6 ("usb: gadget: Add UDC driver for Broadcom USB3.0 device controller IP BDC")

---

Note: I am not sure if these checks were intended to check if the contents of these arrays were NULL or if there should be some other checks in lieu of these; I am not familiar with the USB subsystem to answer this but I will happily respin the patch if this is not correct.

 drivers/usb/gadget/udc/bdc/bdc_ep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/udc/bdc/bdc_ep.c +1 -1
index a4d9b5e1e50e..d49c6dc1082d 100644
@@ -540,7 +540,7 @@ static void bdc_req_complete(struct bdc_ep *ep, struct bdc_req *req,
 {
 	struct bdc *bdc = ep->bdc;
 
-	if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
+	if (req == NULL)
 		return;
 
 	dev_dbg(bdc->dev, "%s ep:%s status:%d\n", __func__, ep->name, status);
Signature · 1 line
2.23.0
#2 lore raw
Quoted 2 lines · Nathan Chancellor

I know it has been a while but ping?

Sorry! Too many bugs...barely treading water! Send help!

Quoted 16 lines · Nathan Chancellor
Quoted 14 lines

When building with Clang + -Wtautological-pointer-compare:

drivers/usb/gadget/udc/bdc/bdc_ep.c:543:28: warning: comparison of address of 'req->queue' equal to a null pointer is always false [-Wtautological-pointer-compare]

        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                             ~~~~~^~~~~    ~~~~
drivers/usb/gadget/udc/bdc/bdc_ep.c:543:51: warning: comparison of
address of 'req->usb_req' equal to a null pointer is always false
[-Wtautological-pointer-compare]
        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                                                    ~~~~~^~~~~~~    ~~~~

2 warnings generated.

Quoted 2 lines
Quoted 2 lines

As it notes, these statements will always evaluate to false so remove them.

req is an instance of a struct bdc_req defined in drivers/usb/gadget/udc/bdc/bdc.h as:
333 struct bdc_req {

334   struct usb_request  usb_req;
335   struct list_head  queue;
336   struct bdc_ep   *ep;
337   /* only one Transfer per request */
338   struct bd_transfer bd_xfr;
339   int epnum;

340 };

So indeed the non-pointer, struct members can never be NULL.

I think the second check that was removed should be req->usb_req.complete == NULL, since otherwise &req->usb_req may be passed to usb_gadget_giveback_request which tries to invoke the complete member as a callback. There are numerous places in drivers/usb/gadget/udc/bdc/bdc_ep.c that assign complete = NULL.

Can the maintainers clarify?

Quoted 35 lines
Quoted 28 lines
Fixes efed421a94e6 ("usb: gadget: Add UDC driver for Broadcom USB3.0 device controller IP BDC")

---

Note: I am not sure if these checks were intended to check if the contents of these arrays were NULL or if there should be some other checks in lieu of these; I am not familiar with the USB subsystem to answer this but I will happily respin the patch if this is not correct.

 drivers/usb/gadget/udc/bdc/bdc_ep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/udc/bdc/bdc_ep.c +1 -2
index a4d9b5e1e50e..d49c6dc1082d 100644
@@ -540,7 +540,7 @@ static void bdc_req_complete(struct bdc_ep *ep, struct bdc_req *req,
 {
      struct bdc *bdc = ep->bdc;
 
-     if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
+     if (req == NULL)
              return;
 
      dev_dbg(bdc->dev, "%s ep:%s status:%d\n", __func__, ep->name, status);
--
Quoted 2 lines

2.23.0

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20200221045740.GA43417%40ubuntu-m2-xlarge-x86.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#3 lore raw
Quoted 39 lines · Nick Desaulniers
Quoted 2 lines · Nathan Chancellor

I know it has been a while but ping?

Sorry! Too many bugs...barely treading water! Send help!

Quoted 16 lines · Nathan Chancellor
Quoted 14 lines

When building with Clang + -Wtautological-pointer-compare:

drivers/usb/gadget/udc/bdc/bdc_ep.c:543:28: warning: comparison of address of 'req->queue' equal to a null pointer is always false [-Wtautological-pointer-compare]

        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                             ~~~~~^~~~~    ~~~~
drivers/usb/gadget/udc/bdc/bdc_ep.c:543:51: warning: comparison of
address of 'req->usb_req' equal to a null pointer is always false
[-Wtautological-pointer-compare]
        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                                                    ~~~~~^~~~~~~    ~~~~

2 warnings generated.

Quoted 2 lines
Quoted 2 lines

As it notes, these statements will always evaluate to false so remove them.

req is an instance of a struct bdc_req defined in drivers/usb/gadget/udc/bdc/bdc.h as:
333 struct bdc_req {

334   struct usb_request  usb_req;
335   struct list_head  queue;
336   struct bdc_ep   *ep;
337   /* only one Transfer per request */
338   struct bd_transfer bd_xfr;
339   int epnum;

340 };

So indeed the non-pointer, struct members can never be NULL.

Quoted 7 lines

I think the second check that was removed should be req->usb_req.complete == NULL, since otherwise &req->usb_req may be passed to usb_gadget_giveback_request which tries to invoke the complete member as a callback. There are numerous places in drivers/usb/gadget/udc/bdc/bdc_ep.c that assign complete = NULL.

Can the maintainers clarify?

$ sed -n 537,555p drivers/usb/gadget/udc/bdc/bdc_ep.c
/* callback to gadget layer when xfr completes */
static void bdc_req_complete(struct bdc_ep *ep, struct bdc_req *req,
						int status)
{
	struct bdc *bdc = ep->bdc;
	if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
		return;

	dev_dbg(bdc->dev, "%s ep:%s status:%d\n", __func__, ep->name, status);
	list_del(&req->queue);
	req->usb_req.status = status;
	usb_gadget_unmap_request(&bdc->gadget, &req->usb_req, ep->dir);
	if (req->usb_req.complete) {
		spin_unlock(&bdc->lock);
		usb_gadget_giveback_request(&ep->usb_ep, &req->usb_req);
		spin_lock(&bdc->lock);
	}
}

It looks like req->usb_req.complete is checked before being passed to usb_gadget_giveback_request. So the patch as it stands is correct, unless those checks needed to be something else.

Felipe, could you clarify or pick up this patch if it is correct? This is one of two warnings that I see for -Wtautological-compare and I want it turned on for 5.7 and it'd be nice to be warning free, especially since I sent this patch back in October :/

Cheers,
Nathan

#4 lore raw

Hi,

Quoted 69 lines · Nathan Chancellor
Quoted 39 lines · Nick Desaulniers
Quoted 2 lines · Nathan Chancellor

I know it has been a while but ping?

Sorry! Too many bugs...barely treading water! Send help!

Quoted 16 lines · Nathan Chancellor
Quoted 14 lines

When building with Clang + -Wtautological-pointer-compare:

drivers/usb/gadget/udc/bdc/bdc_ep.c:543:28: warning: comparison of address of 'req->queue' equal to a null pointer is always false [-Wtautological-pointer-compare]

        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                             ~~~~~^~~~~    ~~~~
drivers/usb/gadget/udc/bdc/bdc_ep.c:543:51: warning: comparison of
address of 'req->usb_req' equal to a null pointer is always false
[-Wtautological-pointer-compare]
        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                                                    ~~~~~^~~~~~~    ~~~~

2 warnings generated.

Quoted 2 lines
Quoted 2 lines

As it notes, these statements will always evaluate to false so remove them.

req is an instance of a struct bdc_req defined in drivers/usb/gadget/udc/bdc/bdc.h as:
333 struct bdc_req {

334   struct usb_request  usb_req;
335   struct list_head  queue;
336   struct bdc_ep   *ep;
337   /* only one Transfer per request */
338   struct bd_transfer bd_xfr;
339   int epnum;

340 };

So indeed the non-pointer, struct members can never be NULL.

Quoted 7 lines

I think the second check that was removed should be req->usb_req.complete == NULL, since otherwise &req->usb_req may be passed to usb_gadget_giveback_request which tries to invoke the complete member as a callback. There are numerous places in drivers/usb/gadget/udc/bdc/bdc_ep.c that assign complete = NULL.

Can the maintainers clarify?

$ sed -n 537,555p drivers/usb/gadget/udc/bdc/bdc_ep.c
/* callback to gadget layer when xfr completes */
static void bdc_req_complete(struct bdc_ep *ep, struct bdc_req *req,
						int status)
{
	struct bdc *bdc = ep->bdc;
	if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
		return;

	dev_dbg(bdc->dev, "%s ep:%s status:%d\n", __func__, ep->name, status);
	list_del(&req->queue);
	req->usb_req.status = status;
	usb_gadget_unmap_request(&bdc->gadget, &req->usb_req, ep->dir);
	if (req->usb_req.complete) {
		spin_unlock(&bdc->lock);
		usb_gadget_giveback_request(&ep->usb_ep, &req->usb_req);
		spin_lock(&bdc->lock);
	}
}
Quoted 8 lines

It looks like req->usb_req.complete is checked before being passed to usb_gadget_giveback_request. So the patch as it stands is correct, unless those checks needed to be something else.

Felipe, could you clarify or pick up this patch if it is correct? This is one of two warnings that I see for -Wtautological-compare and I want it turned on for 5.7 and it'd be nice to be warning free, especially since I sent this patch back in October :/

hmm, I don't have that patch in my inbox. Could you resend it?

Signature · 1 line
balbi
#5 lore raw

PATCH RESEND 1/1 usb: gadget: udc: bdc: Remove unnecessary NULL checks in bdc_req_complete

When building with Clang + -Wtautological-pointer-compare:

drivers/usb/gadget/udc/bdc/bdc_ep.c:543:28: warning: comparison of address of 'req->queue' equal to a null pointer is always false [-Wtautological-pointer-compare]

        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                             ~~~~~^~~~~    ~~~~
drivers/usb/gadget/udc/bdc/bdc_ep.c:543:51: warning: comparison of
address of 'req->usb_req' equal to a null pointer is always false
[-Wtautological-pointer-compare]
        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                                                    ~~~~~^~~~~~~    ~~~~

2 warnings generated.

As it notes, these statements will always evaluate to false so remove them.

Fixes efed421a94e6 ("usb: gadget: Add UDC driver for Broadcom USB3.0 device controller IP BDC")
---
 drivers/usb/gadget/udc/bdc/bdc_ep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/udc/bdc/bdc_ep.c +1 -1
index a4d9b5e1e50e..d49c6dc1082d 100644
@@ -540,7 +540,7 @@ static void bdc_req_complete(struct bdc_ep *ep, struct bdc_req *req,
 {
 	struct bdc *bdc = ep->bdc;
 
-	if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
+	if (req == NULL)
 		return;
 
 	dev_dbg(bdc->dev, "%s ep:%s status:%d\n", __func__, ep->name, status);
Signature · 1 line
2.26.0
#6 lore raw

Hi Nathan,

Quoted 12 lines · Nathan Chancellor

When building with Clang + -Wtautological-pointer-compare:

drivers/usb/gadget/udc/bdc/bdc_ep.c:543:28: warning: comparison of address of 'req->queue' equal to a null pointer is always false [-Wtautological-pointer-compare]

        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                             ~~~~~^~~~~    ~~~~
drivers/usb/gadget/udc/bdc/bdc_ep.c:543:51: warning: comparison of
address of 'req->usb_req' equal to a null pointer is always false
[-Wtautological-pointer-compare]
        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                                                    ~~~~~^~~~~~~    ~~~~
Quoted 8 lines

2 warnings generated.

As it notes, these statements will always evaluate to false so remove them.

Fixes efed421a94e6 ("usb: gadget: Add UDC driver for Broadcom USB3.0 device controller IP BDC")

It's now in my queue for v5.8. It doesn't really look like a bug fix, so it's not going in during v5.7-rc

Signature · 1 line
balbi
#7 lore raw
Quoted 22 lines · Felipe Balbi

Hi Nathan,

Quoted 17 lines · Nathan Chancellor

When building with Clang + -Wtautological-pointer-compare:

drivers/usb/gadget/udc/bdc/bdc_ep.c:543:28: warning: comparison of address of 'req->queue' equal to a null pointer is always false [-Wtautological-pointer-compare]

        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                             ~~~~~^~~~~    ~~~~
drivers/usb/gadget/udc/bdc/bdc_ep.c:543:51: warning: comparison of
address of 'req->usb_req' equal to a null pointer is always false
[-Wtautological-pointer-compare]
        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                                                    ~~~~~^~~~~~~    ~~~~

2 warnings generated.

As it notes, these statements will always evaluate to false so remove them.

Quoted 9 lines
Quoted 3 lines
Fixes efed421a94e6 ("usb: gadget: Add UDC driver for Broadcom USB3.0 device controller IP BDC")

It's now in my queue for v5.8. It doesn't really look like a bug fix, so it's not going in during v5.7-rc

Signature · 1 line
balbi

Thank you for picking it up. It would be nice to see it in 5.7 since we're enabling this warning and this is one of two outstanding instances in -next and the other one's patch has been picked up plus the patch itself is rather benign. Not to mention that I did send this patch back in October. However, when it is merged into Linus' tree is ultimately your call so I won't argue as long as it gets there eventually.

Cheers,
Nathan

#8 lore raw

Hi,

Quoted 27 lines · Nathan Chancellor
Quoted 17 lines
Quoted 17 lines

When building with Clang + -Wtautological-pointer-compare:

drivers/usb/gadget/udc/bdc/bdc_ep.c:543:28: warning: comparison of address of 'req->queue' equal to a null pointer is always false [-Wtautological-pointer-compare]

        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                             ~~~~~^~~~~    ~~~~
drivers/usb/gadget/udc/bdc/bdc_ep.c:543:51: warning: comparison of
address of 'req->usb_req' equal to a null pointer is always false
[-Wtautological-pointer-compare]
        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                                                    ~~~~~^~~~~~~    ~~~~

2 warnings generated.

As it notes, these statements will always evaluate to false so remove them.

Quoted 9 lines
Quoted 3 lines
Fixes efed421a94e6 ("usb: gadget: Add UDC driver for Broadcom USB3.0 device controller IP BDC")

It's now in my queue for v5.8. It doesn't really look like a bug fix, so it's not going in during v5.7-rc

Signature · 1 line
balbi
Quoted 7 lines

Thank you for picking it up. It would be nice to see it in 5.7 since we're enabling this warning and this is one of two outstanding instances in -next and the other one's patch has been picked up plus the patch itself is rather benign. Not to mention that I did send this patch back in October. However, when it is merged into Linus' tree is ultimately your call so I won't argue as long as it gets there eventually.

If Greg's okay with this patch going in during v5.7-rc, I can send it as a fix, no worries. Greg?

Signature · 1 line
balbi
#9 lore raw
Quoted 39 lines · Felipe Balbi

Hi,

Quoted 27 lines · Nathan Chancellor
Quoted 17 lines
Quoted 17 lines

When building with Clang + -Wtautological-pointer-compare:

drivers/usb/gadget/udc/bdc/bdc_ep.c:543:28: warning: comparison of address of 'req->queue' equal to a null pointer is always false [-Wtautological-pointer-compare]

        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                             ~~~~~^~~~~    ~~~~
drivers/usb/gadget/udc/bdc/bdc_ep.c:543:51: warning: comparison of
address of 'req->usb_req' equal to a null pointer is always false
[-Wtautological-pointer-compare]
        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                                                    ~~~~~^~~~~~~    ~~~~

2 warnings generated.

As it notes, these statements will always evaluate to false so remove them.

Quoted 9 lines
Quoted 3 lines
Fixes efed421a94e6 ("usb: gadget: Add UDC driver for Broadcom USB3.0 device controller IP BDC")

It's now in my queue for v5.8. It doesn't really look like a bug fix, so it's not going in during v5.7-rc

Signature · 1 line
balbi
Quoted 7 lines

Thank you for picking it up. It would be nice to see it in 5.7 since we're enabling this warning and this is one of two outstanding instances in -next and the other one's patch has been picked up plus the patch itself is rather benign. Not to mention that I did send this patch back in October. However, when it is merged into Linus' tree is ultimately your call so I won't argue as long as it gets there eventually.

Quoted 2 lines

If Greg's okay with this patch going in during v5.7-rc, I can send it as a fix, no worries. Greg?

Yes, clang build warnings fixes are valid fixes for the -rc period, and I take them into stable where needed as well.

thanks,

greg k-h

#10 lore raw

Hi,

Quoted 35 lines · Greg Kroah-Hartman
Quoted 35 lines
Quoted 34 lines
Quoted 17 lines
Quoted 17 lines

When building with Clang + -Wtautological-pointer-compare:

drivers/usb/gadget/udc/bdc/bdc_ep.c:543:28: warning: comparison of address of 'req->queue' equal to a null pointer is always false [-Wtautological-pointer-compare]

        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                             ~~~~~^~~~~    ~~~~
drivers/usb/gadget/udc/bdc/bdc_ep.c:543:51: warning: comparison of
address of 'req->usb_req' equal to a null pointer is always false
[-Wtautological-pointer-compare]
        if (req == NULL  || &req->queue == NULL || &req->usb_req == NULL)
                                                    ~~~~~^~~~~~~    ~~~~

2 warnings generated.

As it notes, these statements will always evaluate to false so remove them.

Quoted 9 lines
Quoted 3 lines
Fixes efed421a94e6 ("usb: gadget: Add UDC driver for Broadcom USB3.0 device controller IP BDC")

It's now in my queue for v5.8. It doesn't really look like a bug fix, so it's not going in during v5.7-rc

Signature · 1 line
balbi

Thank you for picking it up. It would be nice to see it in 5.7 since we're enabling this warning and this is one of two outstanding instances in -next and the other one's patch has been picked up plus the patch itself is rather benign. Not to mention that I did send this patch back in October. However, when it is merged into Linus' tree is ultimately your call so I won't argue as long as it gets there eventually.

Quoted 5 lines
Quoted 2 lines

If Greg's okay with this patch going in during v5.7-rc, I can send it as a fix, no worries. Greg?

Yes, clang build warnings fixes are valid fixes for the -rc period, and I take them into stable where needed as well.

Thanks for confirming, Greg. I'll move the commit to my testing/fixes

Signature · 1 line
balbi