mirror of
https://github.com/torvalds/linux.git
synced 2024-12-19 09:32:32 +00:00
greybus: introduce cport_id_valid()
Define a public predicate that defines whether a CPort ID is valid. Use it in the message_send() routine, and make the message reported more accurately reflect the error. Also use it to check whether the CPort ID in a received message is valid; if it is not, just drop the message. Get rid of local variable "buffer" in message_send(); it adds no value. Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
parent
2a64fb0e1e
commit
821c620afa
@ -176,21 +176,17 @@ static void *message_send(struct greybus_host_device *hd, u16 cport_id,
|
|||||||
{
|
{
|
||||||
struct es1_ap_dev *es1 = hd_to_es1(hd);
|
struct es1_ap_dev *es1 = hd_to_es1(hd);
|
||||||
struct usb_device *udev = es1->usb_dev;
|
struct usb_device *udev = es1->usb_dev;
|
||||||
void *buffer;
|
|
||||||
size_t buffer_size;
|
size_t buffer_size;
|
||||||
int retval;
|
int retval;
|
||||||
struct urb *urb;
|
struct urb *urb;
|
||||||
|
|
||||||
buffer = message->buffer;
|
|
||||||
buffer_size = sizeof(*message->header) + message->payload_size;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The data actually transferred will include an indication
|
* The data actually transferred will include an indication
|
||||||
* of where the data should be sent. Do one last check of
|
* of where the data should be sent. Do one last check of
|
||||||
* the target CPort id before filling it in.
|
* the target CPort id before filling it in.
|
||||||
*/
|
*/
|
||||||
if (cport_id == CPORT_ID_BAD) {
|
if (!cport_id_valid(cport_id)) {
|
||||||
pr_err("request to send inbound data buffer\n");
|
pr_err("invalid destination cport 0x%02x\n", cport_id);
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,9 +201,11 @@ static void *message_send(struct greybus_host_device *hd, u16 cport_id,
|
|||||||
*/
|
*/
|
||||||
put_unaligned_le16(cport_id, message->header->pad);
|
put_unaligned_le16(cport_id, message->header->pad);
|
||||||
|
|
||||||
|
buffer_size = sizeof(*message->header) + message->payload_size;
|
||||||
|
|
||||||
usb_fill_bulk_urb(urb, udev,
|
usb_fill_bulk_urb(urb, udev,
|
||||||
usb_sndbulkpipe(udev, es1->cport_out_endpoint),
|
usb_sndbulkpipe(udev, es1->cport_out_endpoint),
|
||||||
buffer, buffer_size,
|
message->buffer, buffer_size,
|
||||||
cport_out_callback, message);
|
cport_out_callback, message);
|
||||||
retval = usb_submit_urb(urb, gfp_mask);
|
retval = usb_submit_urb(urb, gfp_mask);
|
||||||
if (retval) {
|
if (retval) {
|
||||||
@ -371,8 +369,12 @@ static void cport_in_callback(struct urb *urb)
|
|||||||
cport_id = get_unaligned_le16(header->pad);
|
cport_id = get_unaligned_le16(header->pad);
|
||||||
put_unaligned_le16(0, header->pad);
|
put_unaligned_le16(0, header->pad);
|
||||||
|
|
||||||
greybus_data_rcvd(hd, cport_id, urb->transfer_buffer,
|
if (cport_id_valid(cport_id))
|
||||||
|
greybus_data_rcvd(hd, cport_id, urb->transfer_buffer,
|
||||||
urb->actual_length);
|
urb->actual_length);
|
||||||
|
else
|
||||||
|
dev_err(dev, "%s: invalid cport id 0x%02x received\n",
|
||||||
|
__func__, cport_id);
|
||||||
exit:
|
exit:
|
||||||
/* put our urb back in the request pool */
|
/* put our urb back in the request pool */
|
||||||
retval = usb_submit_urb(urb, GFP_ATOMIC);
|
retval = usb_submit_urb(urb, GFP_ATOMIC);
|
||||||
|
@ -176,21 +176,17 @@ static void *message_send(struct greybus_host_device *hd, u16 cport_id,
|
|||||||
{
|
{
|
||||||
struct es1_ap_dev *es1 = hd_to_es1(hd);
|
struct es1_ap_dev *es1 = hd_to_es1(hd);
|
||||||
struct usb_device *udev = es1->usb_dev;
|
struct usb_device *udev = es1->usb_dev;
|
||||||
void *buffer;
|
|
||||||
size_t buffer_size;
|
size_t buffer_size;
|
||||||
int retval;
|
int retval;
|
||||||
struct urb *urb;
|
struct urb *urb;
|
||||||
|
|
||||||
buffer = message->buffer;
|
|
||||||
buffer_size = sizeof(*message->header) + message->payload_size;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The data actually transferred will include an indication
|
* The data actually transferred will include an indication
|
||||||
* of where the data should be sent. Do one last check of
|
* of where the data should be sent. Do one last check of
|
||||||
* the target CPort id before filling it in.
|
* the target CPort id before filling it in.
|
||||||
*/
|
*/
|
||||||
if (cport_id == CPORT_ID_BAD) {
|
if (!cport_id_valid(cport_id)) {
|
||||||
pr_err("request to send inbound data buffer\n");
|
pr_err("invalid destination cport 0x%02x\n", cport_id);
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,9 +201,11 @@ static void *message_send(struct greybus_host_device *hd, u16 cport_id,
|
|||||||
*/
|
*/
|
||||||
put_unaligned_le16(cport_id, message->header->pad);
|
put_unaligned_le16(cport_id, message->header->pad);
|
||||||
|
|
||||||
|
buffer_size = sizeof(*message->header) + message->payload_size;
|
||||||
|
|
||||||
usb_fill_bulk_urb(urb, udev,
|
usb_fill_bulk_urb(urb, udev,
|
||||||
usb_sndbulkpipe(udev, es1->cport_out_endpoint),
|
usb_sndbulkpipe(udev, es1->cport_out_endpoint),
|
||||||
buffer, buffer_size,
|
message->buffer, buffer_size,
|
||||||
cport_out_callback, message);
|
cport_out_callback, message);
|
||||||
retval = usb_submit_urb(urb, gfp_mask);
|
retval = usb_submit_urb(urb, gfp_mask);
|
||||||
if (retval) {
|
if (retval) {
|
||||||
@ -371,8 +369,12 @@ static void cport_in_callback(struct urb *urb)
|
|||||||
cport_id = get_unaligned_le16(header->pad);
|
cport_id = get_unaligned_le16(header->pad);
|
||||||
put_unaligned_le16(0, header->pad);
|
put_unaligned_le16(0, header->pad);
|
||||||
|
|
||||||
greybus_data_rcvd(hd, cport_id, urb->transfer_buffer,
|
if (cport_id_valid(cport_id))
|
||||||
|
greybus_data_rcvd(hd, cport_id, urb->transfer_buffer,
|
||||||
urb->actual_length);
|
urb->actual_length);
|
||||||
|
else
|
||||||
|
dev_err(dev, "%s: invalid cport id 0x%02x received\n",
|
||||||
|
__func__, cport_id);
|
||||||
exit:
|
exit:
|
||||||
/* put our urb back in the request pool */
|
/* put our urb back in the request pool */
|
||||||
retval = usb_submit_urb(urb, GFP_ATOMIC);
|
retval = usb_submit_urb(urb, GFP_ATOMIC);
|
||||||
|
@ -196,5 +196,10 @@ static inline int is_gb_connection(const struct device *dev)
|
|||||||
return dev->type == &greybus_connection_type;
|
return dev->type == &greybus_connection_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool cport_id_valid(u16 cport_id)
|
||||||
|
{
|
||||||
|
return cport_id != CPORT_ID_BAD;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* __KERNEL__ */
|
#endif /* __KERNEL__ */
|
||||||
#endif /* __LINUX_GREYBUS_H */
|
#endif /* __LINUX_GREYBUS_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user