Skip to content

Commit 4b83c52

Browse files
committed
rpmsg: Allow callback to return errors
Some rpmsg backends support holding on to and redelivering messages upon failed handling of them, so provide a way for the callback to report and error and allow the backends to handle this. Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
1 parent e88dae5 commit 4b83c52

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

drivers/rpmsg/virtio_rpmsg_bus.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,8 @@ static void rpmsg_xmit_done(struct virtqueue *svq)
791791
}
792792

793793
/* invoked when a name service announcement arrives */
794-
static void rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
795-
void *priv, u32 src)
794+
static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
795+
void *priv, u32 src)
796796
{
797797
struct rpmsg_ns_msg *msg = data;
798798
struct rpmsg_device *newch;
@@ -808,7 +808,7 @@ static void rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
808808

809809
if (len != sizeof(*msg)) {
810810
dev_err(dev, "malformed ns msg (%d)\n", len);
811-
return;
811+
return -EINVAL;
812812
}
813813

814814
/*
@@ -819,7 +819,7 @@ static void rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
819819
*/
820820
if (rpdev) {
821821
dev_err(dev, "anomaly: ns ept has an rpdev handle\n");
822-
return;
822+
return -EINVAL;
823823
}
824824

825825
/* don't trust the remote processor for null terminating the name */
@@ -842,6 +842,8 @@ static void rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
842842
if (!newch)
843843
dev_err(dev, "rpmsg_create_channel failed\n");
844844
}
845+
846+
return 0;
845847
}
846848

847849
static int rpmsg_probe(struct virtio_device *vdev)

include/linux/rpmsg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct rpmsg_device {
8080
const struct rpmsg_device_ops *ops;
8181
};
8282

83-
typedef void (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);
83+
typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);
8484

8585
/**
8686
* struct rpmsg_endpoint - binds a local rpmsg address to its user
@@ -129,7 +129,7 @@ struct rpmsg_driver {
129129
const struct rpmsg_device_id *id_table;
130130
int (*probe)(struct rpmsg_device *dev);
131131
void (*remove)(struct rpmsg_device *dev);
132-
void (*callback)(struct rpmsg_device *, void *, int, void *, u32);
132+
int (*callback)(struct rpmsg_device *, void *, int, void *, u32);
133133
};
134134

135135
int register_rpmsg_device(struct rpmsg_device *dev);

samples/rpmsg/rpmsg_client_sample.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct instance_data {
2828
int rx_count;
2929
};
3030

31-
static void rpmsg_sample_cb(struct rpmsg_device *rpdev, void *data, int len,
31+
static int rpmsg_sample_cb(struct rpmsg_device *rpdev, void *data, int len,
3232
void *priv, u32 src)
3333
{
3434
int ret;
@@ -43,13 +43,15 @@ static void rpmsg_sample_cb(struct rpmsg_device *rpdev, void *data, int len,
4343
/* samples should not live forever */
4444
if (idata->rx_count >= MSG_LIMIT) {
4545
dev_info(&rpdev->dev, "goodbye!\n");
46-
return;
46+
return 0;
4747
}
4848

4949
/* send a new message now */
5050
ret = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
5151
if (ret)
5252
dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
53+
54+
return 0;
5355
}
5456

5557
static int rpmsg_sample_probe(struct rpmsg_device *rpdev)

0 commit comments

Comments
 (0)