soc: qcom: Make qcom_smem_get() return a pointer
Subsystems (2)
PATCH 1/1 soc: qcom: Make qcom_smem_get() return a pointer
Passing a void ** almost always requires a cast at the call site. Instead of littering the code with casts every time this function is called, have qcom_smem_get() return a void pointer to the location of the smem item. This frees the caller from having to cast the pointer with the small downside of doing some extra work to find the item in the case that the caller doesn't care to use the pointer.
---
This is on top of the smd and smem big endian support.
drivers/soc/qcom/smd.c | 30 +++++++++--------- drivers/soc/qcom/smem.c | 73 +++++++++++++++++++------------------------ include/linux/soc/qcom/smem.h | 2 +- 3 files changed, 48 insertions(+), 57 deletions(-)
drivers/soc/qcom/smd.c +15 -15
@@ -1028,10 +1028,11 @@ static struct qcom_smd_channel *qcom_smd_create_channel(struct qcom_smd_edge *edspin_lock_init (&channel->recv_lock);init_waitqueue_head (&channel->fblockread_event); - ret =qcom_smem_get (edge->remote_pid, smem_info_item, (void **)&info, - &info_size); -if (ret) + info =qcom_smem_get (edge->remote_pid, smem_info_item, &info_size); +if (IS_ERR (info)) { + ret =PTR_ERR (info); goto free_name_and_channel; + }/* * Use the size of the item to figure out which channel info struct to
@@ -1048,10 +1049,11 @@ static struct qcom_smd_channel *qcom_smd_create_channel(struct qcom_smd_edge *ed goto free_name_and_channel; } - ret =qcom_smem_get (edge->remote_pid, smem_fifo_item, &fifo_base, - &fifo_size); -if (ret) + fifo_base =qcom_smem_get (edge->remote_pid, smem_fifo_item, &fifo_size); +if (IS_ERR (fifo_base)) { + ret =PTR_ERR (fifo_base); goto free_name_and_channel; + }/* The channel consist of a rx and tx fifo of equal size */ fifo_size /=2 ;
@@ -1088,17 +1090,14 @@ static void qcom_discover_channels(struct qcom_smd_edge *edge)unsigned long flags;unsigned fifo_id;unsigned info_id; -int ret;int tbl;int i;u32 eflags, cid;for (tbl =0 ; tbl <SMD_ALLOC_TBL_COUNT ; tbl++) { - ret =qcom_smem_get (edge->remote_pid, - smem_items[tbl].alloc_tbl_id, - (void **)&alloc_tbl, -NULL ); -if (ret <0 ) + alloc_tbl =qcom_smem_get (edge->remote_pid, + smem_items[tbl].alloc_tbl_id,NULL ); +if (IS_ERR (alloc_tbl))continue ;for (i =0 ; i <SMD_ALLOC_TBL_SIZE ; i++) {
@@ -1278,11 +1277,12 @@ static int qcom_smd_probe(struct platform_device *pdev)int num_edges;int ret;int i =0 ; +void *p;/* Wait for smem */ - ret =qcom_smem_get (QCOM_SMEM_HOST_ANY , smem_items[0 ].alloc_tbl_id,NULL ,NULL ); -if (ret == -EPROBE_DEFER ) -return ret; + p =qcom_smem_get (QCOM_SMEM_HOST_ANY , smem_items[0 ].alloc_tbl_id,NULL ); +if (PTR_ERR (p) == -EPROBE_DEFER ) +return PTR_ERR (p); num_edges =of_get_available_child_count (pdev->dev.of_node); array_size =sizeof (*smd) + num_edges *sizeof (struct qcom_smd_edge );
drivers/soc/qcom/smem.c +32 -41
146 lines not on this page · raw message
include/linux/soc/qcom/smem.h +1 -1
@@ -4,7 +4,7 @@#define QCOM_SMEM_HOST_ANY -1int qcom_smem_alloc (unsigned host,unsigned item,size_t size); -int qcom_smem_get (unsigned host,unsigned item,void **ptr,size_t *size); +void *qcom_smem_get (unsigned host,unsigned item,size_t *size);int qcom_smem_get_free_space (unsigned host);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Quoted 8 lines · Stephen Boyd
Passing a void ** almost always requires a cast at the call site. Instead of littering the code with casts every time this function is called, have
qcom_smem_get()return a void pointer to the location of the smem item. This frees the caller from having to cast the pointer with the small downside of doing some extra work to find the item in the case that the caller doesn't care to use the pointer.
We still need to find the item even if the caller is not interested, to know if we should have returned -ENOENT, so I think it's just a matter of style.
I did have the API to return the pointer earlier in development, but it didn't look good and uniform. But in the final piece, that was picked up, I think it makes more sense (and looks better) to do it this way.
Quoted 5 lines
Signed-off-by Stephen Boyd <[email protected]>---
This is on top of the smd and smem big endian support.
How sneaky of you, then we need to approve those patches before we add new consumers of this API...
Regards,
Bjorn
Quoted 8 lines · Bjorn Andersson
Quoted 5 lines · Stephen Boyd
Signed-off-by Stephen Boyd <[email protected]>---
This is on top of the smd and smem big endian support.
How sneaky of you, then we need to approve those patches before we add new consumers of this API...
I was being explicit to remove any subterfuge. I actually rebased this to the end of the series, so I suspect it will apply fine without the big endian stuff. This was mostly making a note that I tested this on top of those commits.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project