[bug report] usb: typec: ucsi: reorder operations in ucsi_run_command()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Dmitry Baryshkov,

Commit 6cbb7fc91085 ("usb: typec: ucsi: reorder operations in
ucsi_run_command()") from Jun 27, 2024 (linux-next), leads to the
following Smatch static checker warning:

	drivers/usb/typec/ucsi/ucsi.c:151 ucsi_read_error()
	error: uninitialized symbol 'error'.

drivers/usb/typec/ucsi/ucsi.c
    95  static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci,
    96                              void *data, size_t size, bool conn_ack)
    97  {
    98          int ret, err;
    99  
   100          *cci = 0;
   101  
   102          if (size > UCSI_MAX_DATA_LENGTH(ucsi))
   103                  return -EINVAL;
   104  
   105          ret = ucsi->ops->sync_control(ucsi, command);
   106          if (ret)
   107                  return ret;
   108  
   109          ret = ucsi->ops->read_cci(ucsi, cci);
   110          if (ret)
   111                  return ret;
   112  
   113          if (*cci & UCSI_CCI_BUSY)
   114                  return ucsi_run_command(ucsi, UCSI_CANCEL, cci, NULL, 0, false) ?: -EBUSY;
   115  
   116          if (!(*cci & UCSI_CCI_COMMAND_COMPLETE))
   117                  return -EIO;
   118  
   119          if (*cci & UCSI_CCI_NOT_SUPPORTED)
   120                  err = -EOPNOTSUPP;
   121          else if (*cci & UCSI_CCI_ERROR)
   122                  err = -EIO;
   123          else
   124                  err = 0;
   125  
   126          if (!err && data && UCSI_CCI_LENGTH(*cci))
   127                  err = ucsi->ops->read_message_in(ucsi, data, size);

*data is only set when UCSI_CCI_LENGTH(*cci) is non-zero

   128  
   129          /*
   130           * Don't ACK connection change if there was an error.
   131           */
   132          ret = ucsi_acknowledge(ucsi, err ? false : conn_ack);
   133          if (ret)
   134                  return ret;
   135  
   136          return err ?: UCSI_CCI_LENGTH(*cci);

We return zero if err isn't set and UCSI_CCI_LENGTH(*cci) is zero.  There
should probably be a check somewhere that if (!UCSI_CCI_LENGTH(*cci)) return
-EINVAL;

   137  }
   138  
   139  static int ucsi_read_error(struct ucsi *ucsi, u8 connector_num)
   140  {
   141          u64 command;
   142          u16 error;
   143          u32 cci;
   144          int ret;
   145  
   146          command = UCSI_GET_ERROR_STATUS | UCSI_CONNECTOR_NUMBER(connector_num);
   147          ret = ucsi_run_command(ucsi, command, &cci, &error, sizeof(error), false);
   148          if (ret < 0)
   149                  return ret;
   150  
   151          switch (error) {
                        ^^^^^
Uninitialized

   152          case UCSI_ERROR_INCOMPATIBLE_PARTNER:
   153                  return -EOPNOTSUPP;

regards,
dan carpenter




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux