Skip to content

Commit b8077b4

Browse files
krzkandersson
authored andcommitted
rpmsg: Constify buffer passed to send API
The rpmsg_send(), rpmsg_sendto() and other variants of sending interfaces should only send the passed data, without modifying its contents, so mark pointer 'data' as pointer to const. All users of this interface already follow this approach, so only the function declarations have to be updated. Acked-by: Mathieu Poirier <mathieu.poirier@linaro.org> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> Link: https://lore.kernel.org/r/20260317-rpmsg-send-const-v3-3-4d7fd27f037f@oss.qualcomm.com Signed-off-by: Bjorn Andersson <andersson@kernel.org>
1 parent 90dacbf commit b8077b4

7 files changed

Lines changed: 46 additions & 38 deletions

File tree

drivers/rpmsg/mtk_rpmsg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static void mtk_rpmsg_destroy_ept(struct rpmsg_endpoint *ept)
135135
kref_put(&ept->refcount, __mtk_ept_release);
136136
}
137137

138-
static int mtk_rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len)
138+
static int mtk_rpmsg_send(struct rpmsg_endpoint *ept, const void *data, int len)
139139
{
140140
struct mtk_rpmsg_rproc_subdev *mtk_subdev =
141141
to_mtk_rpmsg_endpoint(ept)->mtk_subdev;
@@ -144,7 +144,7 @@ static int mtk_rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len)
144144
len, 0);
145145
}
146146

147-
static int mtk_rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len)
147+
static int mtk_rpmsg_trysend(struct rpmsg_endpoint *ept, const void *data, int len)
148148
{
149149
struct mtk_rpmsg_rproc_subdev *mtk_subdev =
150150
to_mtk_rpmsg_endpoint(ept)->mtk_subdev;

drivers/rpmsg/qcom_glink_native.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ static int qcom_glink_request_intent(struct qcom_glink *glink,
14741474
}
14751475

14761476
static int __qcom_glink_send(struct glink_channel *channel,
1477-
void *data, int len, bool wait)
1477+
const void *data, int len, bool wait)
14781478
{
14791479
struct qcom_glink *glink = channel->glink;
14801480
struct glink_core_rx_intent *intent = NULL;
@@ -1553,28 +1553,31 @@ static int __qcom_glink_send(struct glink_channel *channel,
15531553
return 0;
15541554
}
15551555

1556-
static int qcom_glink_send(struct rpmsg_endpoint *ept, void *data, int len)
1556+
static int qcom_glink_send(struct rpmsg_endpoint *ept, const void *data, int len)
15571557
{
15581558
struct glink_channel *channel = to_glink_channel(ept);
15591559

15601560
return __qcom_glink_send(channel, data, len, true);
15611561
}
15621562

1563-
static int qcom_glink_trysend(struct rpmsg_endpoint *ept, void *data, int len)
1563+
static int qcom_glink_trysend(struct rpmsg_endpoint *ept, const void *data,
1564+
int len)
15641565
{
15651566
struct glink_channel *channel = to_glink_channel(ept);
15661567

15671568
return __qcom_glink_send(channel, data, len, false);
15681569
}
15691570

1570-
static int qcom_glink_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
1571+
static int qcom_glink_sendto(struct rpmsg_endpoint *ept, const void *data,
1572+
int len, u32 dst)
15711573
{
15721574
struct glink_channel *channel = to_glink_channel(ept);
15731575

15741576
return __qcom_glink_send(channel, data, len, true);
15751577
}
15761578

1577-
static int qcom_glink_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
1579+
static int qcom_glink_trysendto(struct rpmsg_endpoint *ept, const void *data,
1580+
int len, u32 dst)
15781581
{
15791582
struct glink_channel *channel = to_glink_channel(ept);
15801583

drivers/rpmsg/qcom_smd.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -960,28 +960,30 @@ static void qcom_smd_destroy_ept(struct rpmsg_endpoint *ept)
960960
kref_put(&ept->refcount, __ept_release);
961961
}
962962

963-
static int qcom_smd_send(struct rpmsg_endpoint *ept, void *data, int len)
963+
static int qcom_smd_send(struct rpmsg_endpoint *ept, const void *data, int len)
964964
{
965965
struct qcom_smd_endpoint *qsept = to_smd_endpoint(ept);
966966

967967
return __qcom_smd_send(qsept->qsch, data, len, true);
968968
}
969969

970-
static int qcom_smd_trysend(struct rpmsg_endpoint *ept, void *data, int len)
970+
static int qcom_smd_trysend(struct rpmsg_endpoint *ept, const void *data, int len)
971971
{
972972
struct qcom_smd_endpoint *qsept = to_smd_endpoint(ept);
973973

974974
return __qcom_smd_send(qsept->qsch, data, len, false);
975975
}
976976

977-
static int qcom_smd_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
977+
static int qcom_smd_sendto(struct rpmsg_endpoint *ept, const void *data, int len,
978+
u32 dst)
978979
{
979980
struct qcom_smd_endpoint *qsept = to_smd_endpoint(ept);
980981

981982
return __qcom_smd_send(qsept->qsch, data, len, true);
982983
}
983984

984-
static int qcom_smd_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
985+
static int qcom_smd_trysendto(struct rpmsg_endpoint *ept, const void *data,
986+
int len, u32 dst)
985987
{
986988
struct qcom_smd_endpoint *qsept = to_smd_endpoint(ept);
987989

drivers/rpmsg/rpmsg_core.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ EXPORT_SYMBOL(rpmsg_destroy_ept);
153153
*
154154
* Return: 0 on success and an appropriate error value on failure.
155155
*/
156-
int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len)
156+
int rpmsg_send(struct rpmsg_endpoint *ept, const void *data, int len)
157157
{
158158
if (WARN_ON(!ept))
159159
return -EINVAL;
@@ -182,7 +182,7 @@ EXPORT_SYMBOL(rpmsg_send);
182182
*
183183
* Return: 0 on success and an appropriate error value on failure.
184184
*/
185-
int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
185+
int rpmsg_sendto(struct rpmsg_endpoint *ept, const void *data, int len, u32 dst)
186186
{
187187
if (WARN_ON(!ept))
188188
return -EINVAL;
@@ -210,7 +210,7 @@ EXPORT_SYMBOL(rpmsg_sendto);
210210
*
211211
* Return: 0 on success and an appropriate error value on failure.
212212
*/
213-
int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len)
213+
int rpmsg_trysend(struct rpmsg_endpoint *ept, const void *data, int len)
214214
{
215215
if (WARN_ON(!ept))
216216
return -EINVAL;
@@ -238,7 +238,7 @@ EXPORT_SYMBOL(rpmsg_trysend);
238238
*
239239
* Return: 0 on success and an appropriate error value on failure.
240240
*/
241-
int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
241+
int rpmsg_trysendto(struct rpmsg_endpoint *ept, const void *data, int len, u32 dst)
242242
{
243243
if (WARN_ON(!ept))
244244
return -EINVAL;

drivers/rpmsg/rpmsg_internal.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ struct rpmsg_device_ops {
6363
struct rpmsg_endpoint_ops {
6464
void (*destroy_ept)(struct rpmsg_endpoint *ept);
6565

66-
int (*send)(struct rpmsg_endpoint *ept, void *data, int len);
67-
int (*sendto)(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
66+
int (*send)(struct rpmsg_endpoint *ept, const void *data, int len);
67+
int (*sendto)(struct rpmsg_endpoint *ept, const void *data, int len, u32 dst);
6868

69-
int (*trysend)(struct rpmsg_endpoint *ept, void *data, int len);
70-
int (*trysendto)(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
69+
int (*trysend)(struct rpmsg_endpoint *ept, const void *data, int len);
70+
int (*trysendto)(struct rpmsg_endpoint *ept, const void *data, int len, u32 dst);
7171
__poll_t (*poll)(struct rpmsg_endpoint *ept, struct file *filp,
7272
poll_table *wait);
7373
int (*set_flow_control)(struct rpmsg_endpoint *ept, bool pause, u32 dst);

drivers/rpmsg/virtio_rpmsg_bus.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ struct virtio_rpmsg_channel {
136136
#define RPMSG_RESERVED_ADDRESSES (1024)
137137

138138
static void virtio_rpmsg_destroy_ept(struct rpmsg_endpoint *ept);
139-
static int virtio_rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len);
140-
static int virtio_rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len,
141-
u32 dst);
142-
static int virtio_rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len);
143-
static int virtio_rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data,
139+
static int virtio_rpmsg_send(struct rpmsg_endpoint *ept, const void *data, int len);
140+
static int virtio_rpmsg_sendto(struct rpmsg_endpoint *ept, const void *data,
141+
int len, u32 dst);
142+
static int virtio_rpmsg_trysend(struct rpmsg_endpoint *ept, const void *data,
143+
int len);
144+
static int virtio_rpmsg_trysendto(struct rpmsg_endpoint *ept, const void *data,
144145
int len, u32 dst);
145146
static __poll_t virtio_rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp,
146147
poll_table *wait);
@@ -490,7 +491,7 @@ static void *get_a_tx_buf(struct virtproc_info *vrp)
490491
*/
491492
static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
492493
u32 src, u32 dst,
493-
void *data, int len, bool wait)
494+
const void *data, int len, bool wait)
494495
{
495496
struct virtio_rpmsg_channel *vch = to_virtio_rpmsg_channel(rpdev);
496497
struct virtproc_info *vrp = vch->vrp;
@@ -580,32 +581,33 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
580581
return err;
581582
}
582583

583-
static int virtio_rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len)
584+
static int virtio_rpmsg_send(struct rpmsg_endpoint *ept, const void *data, int len)
584585
{
585586
struct rpmsg_device *rpdev = ept->rpdev;
586587
u32 src = ept->addr, dst = rpdev->dst;
587588

588589
return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true);
589590
}
590591

591-
static int virtio_rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len,
592-
u32 dst)
592+
static int virtio_rpmsg_sendto(struct rpmsg_endpoint *ept, const void *data,
593+
int len, u32 dst)
593594
{
594595
struct rpmsg_device *rpdev = ept->rpdev;
595596
u32 src = ept->addr;
596597

597598
return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true);
598599
}
599600

600-
static int virtio_rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len)
601+
static int virtio_rpmsg_trysend(struct rpmsg_endpoint *ept, const void *data,
602+
int len)
601603
{
602604
struct rpmsg_device *rpdev = ept->rpdev;
603605
u32 src = ept->addr, dst = rpdev->dst;
604606

605607
return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, false);
606608
}
607609

608-
static int virtio_rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data,
610+
static int virtio_rpmsg_trysendto(struct rpmsg_endpoint *ept, const void *data,
609611
int len, u32 dst)
610612
{
611613
struct rpmsg_device *rpdev = ept->rpdev;

include/linux/rpmsg.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@ struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *,
182182
rpmsg_rx_cb_t cb, void *priv,
183183
struct rpmsg_channel_info chinfo);
184184

185-
int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len);
186-
int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
185+
int rpmsg_send(struct rpmsg_endpoint *ept, const void *data, int len);
186+
int rpmsg_sendto(struct rpmsg_endpoint *ept, const void *data, int len, u32 dst);
187187

188-
int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len);
189-
int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
188+
int rpmsg_trysend(struct rpmsg_endpoint *ept, const void *data, int len);
189+
int rpmsg_trysendto(struct rpmsg_endpoint *ept, const void *data, int len, u32 dst);
190190

191191
__poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp,
192192
poll_table *wait);
@@ -249,15 +249,15 @@ static inline struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev
249249
return NULL;
250250
}
251251

252-
static inline int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len)
252+
static inline int rpmsg_send(struct rpmsg_endpoint *ept, const void *data, int len)
253253
{
254254
/* This shouldn't be possible */
255255
WARN_ON(1);
256256

257257
return -ENXIO;
258258
}
259259

260-
static inline int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len,
260+
static inline int rpmsg_sendto(struct rpmsg_endpoint *ept, const void *data, int len,
261261
u32 dst)
262262
{
263263
/* This shouldn't be possible */
@@ -267,15 +267,16 @@ static inline int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len,
267267

268268
}
269269

270-
static inline int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len)
270+
static inline int rpmsg_trysend(struct rpmsg_endpoint *ept, const void *data,
271+
int len)
271272
{
272273
/* This shouldn't be possible */
273274
WARN_ON(1);
274275

275276
return -ENXIO;
276277
}
277278

278-
static inline int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data,
279+
static inline int rpmsg_trysendto(struct rpmsg_endpoint *ept, const void *data,
279280
int len, u32 dst)
280281
{
281282
/* This shouldn't be possible */

0 commit comments

Comments
 (0)