Commit 93e93244 authored by Bjorn Andersson's avatar Bjorn Andersson

rpmsg: Handle invalid parameters in public API

There are two cases of possible uninitialized pointer usage in the API,
either the parameters themselves are invalid or we're trying to jump to
functions not required to be implemented by all backends.
Suggested-by: default avatarLoic Pallardy <loic.pallardy@st.com>
Signed-off-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
parent bbd18809
...@@ -71,6 +71,9 @@ struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev, ...@@ -71,6 +71,9 @@ struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev,
rpmsg_rx_cb_t cb, void *priv, rpmsg_rx_cb_t cb, void *priv,
struct rpmsg_channel_info chinfo) struct rpmsg_channel_info chinfo)
{ {
if (WARN_ON(!rpdev))
return ERR_PTR(-EINVAL);
return rpdev->ops->create_ept(rpdev, cb, priv, chinfo); return rpdev->ops->create_ept(rpdev, cb, priv, chinfo);
} }
EXPORT_SYMBOL(rpmsg_create_ept); EXPORT_SYMBOL(rpmsg_create_ept);
...@@ -80,10 +83,12 @@ EXPORT_SYMBOL(rpmsg_create_ept); ...@@ -80,10 +83,12 @@ EXPORT_SYMBOL(rpmsg_create_ept);
* @ept: endpoing to destroy * @ept: endpoing to destroy
* *
* Should be used by drivers to destroy an rpmsg endpoint previously * Should be used by drivers to destroy an rpmsg endpoint previously
* created with rpmsg_create_ept(). * created with rpmsg_create_ept(). As with other types of "free" NULL
* is a valid parameter.
*/ */
void rpmsg_destroy_ept(struct rpmsg_endpoint *ept) void rpmsg_destroy_ept(struct rpmsg_endpoint *ept)
{ {
if (ept)
ept->ops->destroy_ept(ept); ept->ops->destroy_ept(ept);
} }
EXPORT_SYMBOL(rpmsg_destroy_ept); EXPORT_SYMBOL(rpmsg_destroy_ept);
...@@ -108,6 +113,11 @@ EXPORT_SYMBOL(rpmsg_destroy_ept); ...@@ -108,6 +113,11 @@ EXPORT_SYMBOL(rpmsg_destroy_ept);
*/ */
int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len) int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len)
{ {
if (WARN_ON(!ept))
return -EINVAL;
if (!ept->ops->send)
return -ENXIO;
return ept->ops->send(ept, data, len); return ept->ops->send(ept, data, len);
} }
EXPORT_SYMBOL(rpmsg_send); EXPORT_SYMBOL(rpmsg_send);
...@@ -132,6 +142,11 @@ EXPORT_SYMBOL(rpmsg_send); ...@@ -132,6 +142,11 @@ EXPORT_SYMBOL(rpmsg_send);
*/ */
int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst) int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
{ {
if (WARN_ON(!ept))
return -EINVAL;
if (!ept->ops->sendto)
return -ENXIO;
return ept->ops->sendto(ept, data, len, dst); return ept->ops->sendto(ept, data, len, dst);
} }
EXPORT_SYMBOL(rpmsg_sendto); EXPORT_SYMBOL(rpmsg_sendto);
...@@ -159,6 +174,11 @@ EXPORT_SYMBOL(rpmsg_sendto); ...@@ -159,6 +174,11 @@ EXPORT_SYMBOL(rpmsg_sendto);
int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
void *data, int len) void *data, int len)
{ {
if (WARN_ON(!ept))
return -EINVAL;
if (!ept->ops->send_offchannel)
return -ENXIO;
return ept->ops->send_offchannel(ept, src, dst, data, len); return ept->ops->send_offchannel(ept, src, dst, data, len);
} }
EXPORT_SYMBOL(rpmsg_send_offchannel); EXPORT_SYMBOL(rpmsg_send_offchannel);
...@@ -182,6 +202,11 @@ EXPORT_SYMBOL(rpmsg_send_offchannel); ...@@ -182,6 +202,11 @@ EXPORT_SYMBOL(rpmsg_send_offchannel);
*/ */
int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len) int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len)
{ {
if (WARN_ON(!ept))
return -EINVAL;
if (!ept->ops->trysend)
return -ENXIO;
return ept->ops->trysend(ept, data, len); return ept->ops->trysend(ept, data, len);
} }
EXPORT_SYMBOL(rpmsg_trysend); EXPORT_SYMBOL(rpmsg_trysend);
...@@ -205,6 +230,11 @@ EXPORT_SYMBOL(rpmsg_trysend); ...@@ -205,6 +230,11 @@ EXPORT_SYMBOL(rpmsg_trysend);
*/ */
int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst) int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
{ {
if (WARN_ON(!ept))
return -EINVAL;
if (!ept->ops->trysendto)
return -ENXIO;
return ept->ops->trysendto(ept, data, len, dst); return ept->ops->trysendto(ept, data, len, dst);
} }
EXPORT_SYMBOL(rpmsg_trysendto); EXPORT_SYMBOL(rpmsg_trysendto);
...@@ -231,6 +261,11 @@ EXPORT_SYMBOL(rpmsg_trysendto); ...@@ -231,6 +261,11 @@ EXPORT_SYMBOL(rpmsg_trysendto);
int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
void *data, int len) void *data, int len)
{ {
if (WARN_ON(!ept))
return -EINVAL;
if (!ept->ops->trysend_offchannel)
return -ENXIO;
return ept->ops->trysend_offchannel(ept, src, dst, data, len); return ept->ops->trysend_offchannel(ept, src, dst, data, len);
} }
EXPORT_SYMBOL(rpmsg_trysend_offchannel); EXPORT_SYMBOL(rpmsg_trysend_offchannel);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment