diff mbox series

[2/2] iio: buffer: Return error if no callback is given

Message ID 20201121161457.957-3-nuno.sa@analog.com (mailing list archive)
State New, archived
Headers show
Series Make cb a required parameter of buffer-cb | expand

Commit Message

Sa, Nuno Nov. 21, 2020, 4:14 p.m. UTC
Return error in case no callback is provided to
`iio_channel_get_all_cb()`. There's no point in setting up a buffer-cb
if no callback is provided.

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
 drivers/iio/buffer/industrialio-buffer-cb.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Olivier MOYSAN Nov. 23, 2020, 8:40 a.m. UTC | #1
On 11/21/20 5:14 PM, Nuno Sá wrote:
> Return error in case no callback is provided to
> `iio_channel_get_all_cb()`. There's no point in setting up a buffer-cb
> if no callback is provided.
> 
> Signed-off-by: Nuno Sá <nuno.sa@analog.com>
> ---
>   drivers/iio/buffer/industrialio-buffer-cb.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/iio/buffer/industrialio-buffer-cb.c b/drivers/iio/buffer/industrialio-buffer-cb.c
> index 47c96f7f4976..4c12b7a94af5 100644
> --- a/drivers/iio/buffer/industrialio-buffer-cb.c
> +++ b/drivers/iio/buffer/industrialio-buffer-cb.c
> @@ -54,6 +54,11 @@ struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev,
>   	struct iio_cb_buffer *cb_buff;
>   	struct iio_channel *chan;
>   
> +	if (!cb) {
> +		dev_err(dev, "Invalid arguments: A callback must be provided!\n");
> +		return ERR_PTR(-EINVAL);
> +	}
> +
>   	cb_buff = kzalloc(sizeof(*cb_buff), GFP_KERNEL);
>   	if (cb_buff == NULL)
>   		return ERR_PTR(-ENOMEM);
> 

Reviewed-by: Olivier Moysan <olivier.moysan@st.com>

Best regards,
Olivier
diff mbox series

Patch

diff --git a/drivers/iio/buffer/industrialio-buffer-cb.c b/drivers/iio/buffer/industrialio-buffer-cb.c
index 47c96f7f4976..4c12b7a94af5 100644
--- a/drivers/iio/buffer/industrialio-buffer-cb.c
+++ b/drivers/iio/buffer/industrialio-buffer-cb.c
@@ -54,6 +54,11 @@  struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev,
 	struct iio_cb_buffer *cb_buff;
 	struct iio_channel *chan;
 
+	if (!cb) {
+		dev_err(dev, "Invalid arguments: A callback must be provided!\n");
+		return ERR_PTR(-EINVAL);
+	}
+
 	cb_buff = kzalloc(sizeof(*cb_buff), GFP_KERNEL);
 	if (cb_buff == NULL)
 		return ERR_PTR(-ENOMEM);