From: Dan Carpenter <error27@gmail.com>
To: bhanumaiya@chromium.org
Cc: chrome-platform@lists.linux.dev
Subject: [bug report] platform/chrome: cros_ec_uart: Add transport layer
Date: Fri, 6 Jan 2023 11:54:27 +0300 [thread overview]
Message-ID: <Y7fhw4S7Tb0GcHMF@kili> (raw)
Hello Bhanu Prakash Maiya,
The patch 04a8bdd135cc: "platform/chrome: cros_ec_uart: Add transport
layer" from Dec 27, 2022, leads to the following Smatch static
checker warning:
drivers/platform/chrome/cros_ec_uart.c:152 cros_ec_uart_pkt_xfer()
warn: 'ret' possible negative type promoted to high
drivers/platform/chrome/cros_ec_uart.c
130 static int cros_ec_uart_pkt_xfer(struct cros_ec_device *ec_dev,
131 struct cros_ec_command *ec_msg)
132 {
133 struct cros_ec_uart *ec_uart = ec_dev->priv;
134 struct serdev_device *serdev = ec_uart->serdev;
135 struct response_info *resp = &ec_uart->response;
136 struct ec_host_response *host_response;
137 unsigned int len;
^^^^^^^^^^^^^^^^
138 int ret, i;
139 u8 sum;
140
141 len = cros_ec_prepare_tx(ec_dev, ec_msg);
142 dev_dbg(ec_dev->dev, "Prepared len=%d\n", len);
143
144 /* Setup for incoming response */
145 resp->data = ec_dev->din;
146 resp->max_size = ec_dev->din_size;
147 resp->size = 0;
148 resp->exp_len = 0;
149 resp->status = 0;
150
151 ret = serdev_device_write_buf(serdev, ec_dev->dout, len);
--> 152 if (ret < len) {
If serdev_device_write_buf() returns negative then type promotion means
this condition is false. Write it like:
if (ret < 0 || ret != len) {
dev_err(ec_dev->dev, "Unable to write data\n");
if (ret >= 0)
ret = -EIO;
goto exit;
}
153 dev_err(ec_dev->dev, "Unable to write data\n");
154 ret = -EIO;
155 goto exit;
156 }
157
158 ret = wait_event_timeout(resp->wait_queue, resp->status,
159 msecs_to_jiffies(EC_MSG_DEADLINE_MS));
160 if (ret == 0) {
161 dev_warn(ec_dev->dev, "Timed out waiting for response.\n");
162 ret = -ETIMEDOUT;
163 goto exit;
164 }
165
166 if (resp->status < 0) {
167 ret = resp->status;
168 dev_warn(ec_dev->dev, "Error response received: %d\n", ret);
169 goto exit;
170 }
171
172 host_response = (struct ec_host_response *)ec_dev->din;
173 ec_msg->result = host_response->result;
174
175 if (host_response->data_len > ec_msg->insize) {
176 dev_err(ec_dev->dev, "Resp too long (%d bytes, expected %d)\n",
177 host_response->data_len, ec_msg->insize);
178 ret = -ENOSPC;
ret = -EINVAL; (Unless you are discussing harddrives).
179 goto exit;
180 }
181
182 /* Validate checksum */
183 sum = 0;
184 for (i = 0; i < sizeof(*host_response) + host_response->data_len; i++)
185 sum += ec_dev->din[i];
186
187 if (sum) {
188 dev_err(ec_dev->dev, "Bad packet checksum calculated %x\n", sum);
189 ret = -EBADMSG;
190 goto exit;
191 }
192
193 memcpy(ec_msg->data, ec_dev->din + sizeof(*host_response), host_response->data_len);
194
195 ret = host_response->data_len;
196
197 exit:
198 /* Invalidate response buffer to guard against out of band rx data */
199 resp->data = NULL;
200
201 if (ec_msg->command == EC_CMD_REBOOT_EC)
202 msleep(EC_REBOOT_DELAY_MS);
203
204 return ret;
205 }
regards,
dan carpenter
next reply other threads:[~2023-01-06 8:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-06 8:54 Dan Carpenter [this message]
2023-01-10 3:25 ` [bug report] platform/chrome: cros_ec_uart: Add transport layer Tzung-Bi Shih
2023-01-10 5:16 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y7fhw4S7Tb0GcHMF@kili \
--to=error27@gmail.com \
--cc=bhanumaiya@chromium.org \
--cc=chrome-platform@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.