All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] i3c: master: svc: Add Silvaco I3C master driver
@ 2021-02-09 10:57 Dan Carpenter
  2021-02-16 15:21 ` Miquel Raynal
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2021-02-09 10:57 UTC (permalink / raw)
  To: miquel.raynal; +Cc: linux-i3c

Hello Miquel Raynal,

The patch dd3c52846d59: "i3c: master: svc: Add Silvaco I3C master
driver" from Jan 21, 2021, leads to the following static checker
warning:

	drivers/i3c/master/svc-i3c-master.c:394 svc_i3c_master_ibi_work()
	error: uninitialized symbol 'dev'.

drivers/i3c/master/svc-i3c-master.c
   364          status = readl(master->regs + SVC_I3C_MSTATUS);
   365          ibitype = SVC_I3C_MSTATUS_IBITYPE(status);
   366          ibiaddr = SVC_I3C_MSTATUS_IBIADDR(status);
   367  
   368          /* Handle the critical responses to IBI's */
   369          switch (ibitype) {
   370          case SVC_I3C_MSTATUS_IBITYPE_IBI:
   371                  dev = svc_i3c_master_dev_from_addr(master, ibiaddr);
   372                  if (!dev)
   373                          svc_i3c_master_nack_ibi(master);
   374                  else
   375                          svc_i3c_master_handle_ibi(master, dev);

"dev" only valid on this path.

   376                  break;
   377          case SVC_I3C_MSTATUS_IBITYPE_HOT_JOIN:
   378                  svc_i3c_master_ack_ibi(master, false);
   379                  break;
   380          case SVC_I3C_MSTATUS_IBITYPE_MASTER_REQUEST:
   381                  svc_i3c_master_nack_ibi(master);
   382                  break;
   383          default:
   384                  break;
   385          }
   386  
   387          /*
   388           * If an error happened, we probably got interrupted and the exchange
   389           * timedout. In this case we just drop everything, emit a stop and wait
   390           * for the slave to interrupt again.
   391           */
   392          if (svc_i3c_master_error(master)) {
   393                  if (master->ibi.tbq_slot) {
   394                          data = i3c_dev_get_master_data(dev);
                                                               ^^^
Dereferenced here.

   395                          i3c_generic_ibi_recycle_slot(data->ibi_pool,
   396                                                       master->ibi.tbq_slot);
   397                          master->ibi.tbq_slot = NULL;
   398                  }
   399  
   400                  svc_i3c_master_emit_stop(master);
   401  
   402                  goto reenable_ibis;
   403          }
   404  
   405          /* Handle the non critical tasks */

regards,
dan carpenter

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* Re: [bug report] i3c: master: svc: Add Silvaco I3C master driver
  2021-02-09 10:57 [bug report] i3c: master: svc: Add Silvaco I3C master driver Dan Carpenter
@ 2021-02-16 15:21 ` Miquel Raynal
  2021-02-16 18:44   ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Miquel Raynal @ 2021-02-16 15:21 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-i3c

Hi Dan,

Thanks for the report.

Dan Carpenter <dan.carpenter@oracle.com> wrote on Tue, 9 Feb 2021
13:57:28 +0300:

> Hello Miquel Raynal,
> 
> The patch dd3c52846d59: "i3c: master: svc: Add Silvaco I3C master
> driver" from Jan 21, 2021, leads to the following static checker
> warning:
> 
> 	drivers/i3c/master/svc-i3c-master.c:394 svc_i3c_master_ibi_work()
> 	error: uninitialized symbol 'dev'.
> 
> drivers/i3c/master/svc-i3c-master.c
>    364          status = readl(master->regs + SVC_I3C_MSTATUS);
>    365          ibitype = SVC_I3C_MSTATUS_IBITYPE(status);
>    366          ibiaddr = SVC_I3C_MSTATUS_IBIADDR(status);
>    367  
>    368          /* Handle the critical responses to IBI's */
>    369          switch (ibitype) {
>    370          case SVC_I3C_MSTATUS_IBITYPE_IBI:
>    371                  dev = svc_i3c_master_dev_from_addr(master, ibiaddr);
>    372                  if (!dev)
>    373                          svc_i3c_master_nack_ibi(master);
>    374                  else
>    375                          svc_i3c_master_handle_ibi(master, dev);
> 
> "dev" only valid on this path.
> 
>    376                  break;
>    377          case SVC_I3C_MSTATUS_IBITYPE_HOT_JOIN:
>    378                  svc_i3c_master_ack_ibi(master, false);
>    379                  break;
>    380          case SVC_I3C_MSTATUS_IBITYPE_MASTER_REQUEST:
>    381                  svc_i3c_master_nack_ibi(master);
>    382                  break;
>    383          default:
>    384                  break;
>    385          }
>    386  
>    387          /*
>    388           * If an error happened, we probably got interrupted and the exchange
>    389           * timedout. In this case we just drop everything, emit a stop and wait
>    390           * for the slave to interrupt again.
>    391           */
>    392          if (svc_i3c_master_error(master)) {
>    393                  if (master->ibi.tbq_slot) {
>    394                          data = i3c_dev_get_master_data(dev);
>                                                                ^^^
> Dereferenced here.

Only svc_i3c_master_handle_ibi() populates master->ibi.tbq_slot, so dev
will only be dereferenced if svc_i3c_master_handle_ibi() was executed,
which only happens if dev is valid.

I don't think there is a risk here, however if robots really are
unhappy we might add an extra sanity level by checking dev explicitly,
but this would be purely useless on a practical point of view.

Thanks,
Miquèl

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* Re: [bug report] i3c: master: svc: Add Silvaco I3C master driver
  2021-02-16 15:21 ` Miquel Raynal
@ 2021-02-16 18:44   ` Dan Carpenter
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2021-02-16 18:44 UTC (permalink / raw)
  To: Miquel Raynal; +Cc: linux-i3c

On Tue, Feb 16, 2021 at 04:21:01PM +0100, Miquel Raynal wrote:
> Hi Dan,
> 
> Thanks for the report.
> 
> Dan Carpenter <dan.carpenter@oracle.com> wrote on Tue, 9 Feb 2021
> 13:57:28 +0300:
> 
> > Hello Miquel Raynal,
> > 
> > The patch dd3c52846d59: "i3c: master: svc: Add Silvaco I3C master
> > driver" from Jan 21, 2021, leads to the following static checker
> > warning:
> > 
> > 	drivers/i3c/master/svc-i3c-master.c:394 svc_i3c_master_ibi_work()
> > 	error: uninitialized symbol 'dev'.
> > 
> > drivers/i3c/master/svc-i3c-master.c
> >    364          status = readl(master->regs + SVC_I3C_MSTATUS);
> >    365          ibitype = SVC_I3C_MSTATUS_IBITYPE(status);
> >    366          ibiaddr = SVC_I3C_MSTATUS_IBIADDR(status);
> >    367  
> >    368          /* Handle the critical responses to IBI's */
> >    369          switch (ibitype) {
> >    370          case SVC_I3C_MSTATUS_IBITYPE_IBI:
> >    371                  dev = svc_i3c_master_dev_from_addr(master, ibiaddr);
> >    372                  if (!dev)
> >    373                          svc_i3c_master_nack_ibi(master);
> >    374                  else
> >    375                          svc_i3c_master_handle_ibi(master, dev);
> > 
> > "dev" only valid on this path.
> > 
> >    376                  break;
> >    377          case SVC_I3C_MSTATUS_IBITYPE_HOT_JOIN:
> >    378                  svc_i3c_master_ack_ibi(master, false);
> >    379                  break;
> >    380          case SVC_I3C_MSTATUS_IBITYPE_MASTER_REQUEST:
> >    381                  svc_i3c_master_nack_ibi(master);
> >    382                  break;
> >    383          default:
> >    384                  break;
> >    385          }
> >    386  
> >    387          /*
> >    388           * If an error happened, we probably got interrupted and the exchange
> >    389           * timedout. In this case we just drop everything, emit a stop and wait
> >    390           * for the slave to interrupt again.
> >    391           */
> >    392          if (svc_i3c_master_error(master)) {
> >    393                  if (master->ibi.tbq_slot) {
> >    394                          data = i3c_dev_get_master_data(dev);
> >                                                                ^^^
> > Dereferenced here.
> 
> Only svc_i3c_master_handle_ibi() populates master->ibi.tbq_slot, so dev
> will only be dereferenced if svc_i3c_master_handle_ibi() was executed,
> which only happens if dev is valid.
> 
> I don't think there is a risk here, however if robots really are
> unhappy we might add an extra sanity level by checking dev explicitly,
> but this would be purely useless on a practical point of view.

Nah.  I think this works.  It's fine.  Don't do things just to make the
robots happy.

regards,
dan carpenter


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* Re: [bug report] i3c: master: svc: Add Silvaco I3C master driver
  2021-07-26  7:33 Dan Carpenter
@ 2021-07-26  8:48 ` Miquel Raynal
  0 siblings, 0 replies; 5+ messages in thread
From: Miquel Raynal @ 2021-07-26  8:48 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-i3c

Hi Dan,

Dan Carpenter <dan.carpenter@oracle.com> wrote on Mon, 26 Jul 2021
10:33:19 +0300:

> Hello Miquel Raynal,
> 
> The patch dd3c52846d59: "i3c: master: svc: Add Silvaco I3C master
> driver" from Jan 21, 2021, leads to the following static checker
> warning:
> 
> 	drivers/i3c/master/svc-i3c-master.c:690 svc_i3c_master_do_daa_locked()
> 	warn: sleeping in atomic context
> 
> drivers/i3c/master/svc-i3c-master.c
>     670 static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master,
>     671 					u8 *addrs, unsigned int *count)
>     672 {
>     673 	u64 prov_id[SVC_I3C_MAX_DEVS] = {}, nacking_prov_id = 0;
>     674 	unsigned int dev_nb = 0, last_addr = 0;
>     675 	u32 reg;
>     676 	int ret, i;
>     677 
>     678 	while (true) {
>     679 		/* Enter/proceed with DAA */
>     680 		writel(SVC_I3C_MCTRL_REQUEST_PROC_DAA |
>     681 		       SVC_I3C_MCTRL_TYPE_I3C |
>     682 		       SVC_I3C_MCTRL_IBIRESP_NACK |
>     683 		       SVC_I3C_MCTRL_DIR(SVC_I3C_MCTRL_DIR_WRITE),
>     684 		       master->regs + SVC_I3C_MCTRL);
>     685 
>     686 		/*
>     687 		 * Either one slave will send its ID, or the assignment process
>     688 		 * is done.
>     689 		 */
> --> 690 		ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg,  
>     691 					 SVC_I3C_MSTATUS_RXPEND(reg) |
>     692 					 SVC_I3C_MSTATUS_MCTRLDONE(reg),
>     693 					 1, 1000);
>                                                  ^
> This is called with a lock held and the code is doing a 1 us sleep.

Yes, there is a pending patch for this:
https://lore.kernel.org/patchwork/patch/1461520/

Thanks anyway for the report!

Thanks,
Miquèl

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

* [bug report] i3c: master: svc: Add Silvaco I3C master driver
@ 2021-07-26  7:33 Dan Carpenter
  2021-07-26  8:48 ` Miquel Raynal
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2021-07-26  7:33 UTC (permalink / raw)
  To: miquel.raynal; +Cc: linux-i3c

Hello Miquel Raynal,

The patch dd3c52846d59: "i3c: master: svc: Add Silvaco I3C master
driver" from Jan 21, 2021, leads to the following static checker
warning:

	drivers/i3c/master/svc-i3c-master.c:690 svc_i3c_master_do_daa_locked()
	warn: sleeping in atomic context

drivers/i3c/master/svc-i3c-master.c
    670 static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master,
    671 					u8 *addrs, unsigned int *count)
    672 {
    673 	u64 prov_id[SVC_I3C_MAX_DEVS] = {}, nacking_prov_id = 0;
    674 	unsigned int dev_nb = 0, last_addr = 0;
    675 	u32 reg;
    676 	int ret, i;
    677 
    678 	while (true) {
    679 		/* Enter/proceed with DAA */
    680 		writel(SVC_I3C_MCTRL_REQUEST_PROC_DAA |
    681 		       SVC_I3C_MCTRL_TYPE_I3C |
    682 		       SVC_I3C_MCTRL_IBIRESP_NACK |
    683 		       SVC_I3C_MCTRL_DIR(SVC_I3C_MCTRL_DIR_WRITE),
    684 		       master->regs + SVC_I3C_MCTRL);
    685 
    686 		/*
    687 		 * Either one slave will send its ID, or the assignment process
    688 		 * is done.
    689 		 */
--> 690 		ret = readl_poll_timeout(master->regs + SVC_I3C_MSTATUS, reg,
    691 					 SVC_I3C_MSTATUS_RXPEND(reg) |
    692 					 SVC_I3C_MSTATUS_MCTRLDONE(reg),
    693 					 1, 1000);
                                                 ^
This is called with a lock held and the code is doing a 1 us sleep.

    694 		if (ret)
    695 			return ret;
    696 

regards,
dan carpenter

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

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

end of thread, other threads:[~2021-07-26  8:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-09 10:57 [bug report] i3c: master: svc: Add Silvaco I3C master driver Dan Carpenter
2021-02-16 15:21 ` Miquel Raynal
2021-02-16 18:44   ` Dan Carpenter
2021-07-26  7:33 Dan Carpenter
2021-07-26  8:48 ` Miquel Raynal

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.