diff mbox series

[RFC,1/1] iio: buffer: Sanity check buffer callback

Message ID 20201112151334.32167-2-nuno.sa@analog.com (mailing list archive)
State New, archived
Headers show
Series Sanity check buffer callback | expand

Commit Message

Nuno Sa Nov. 12, 2020, 3:13 p.m. UTC
Make sure that a callback is actually present before trying to call
it...

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

Comments

Lars-Peter Clausen Nov. 12, 2020, 4:15 p.m. UTC | #1
On 11/12/20 4:13 PM, Nuno Sá wrote:
> Make sure that a callback is actually present before trying to call
> it...
>
> Signed-off-by: Nuno Sá <nuno.sa@analog.com>
> ---
>   drivers/iio/buffer/industrialio-buffer-cb.c | 4 ++++
>   1 file changed, 4 insertions(+)
>
> diff --git a/drivers/iio/buffer/industrialio-buffer-cb.c b/drivers/iio/buffer/industrialio-buffer-cb.c
> index 47c96f7f4976..b4385f59399d 100644
> --- a/drivers/iio/buffer/industrialio-buffer-cb.c
> +++ b/drivers/iio/buffer/industrialio-buffer-cb.c
> @@ -27,6 +27,10 @@ static struct iio_cb_buffer *buffer_to_cb_buffer(struct iio_buffer *buffer)
>   static int iio_buffer_cb_store_to(struct iio_buffer *buffer, const void *data)
>   {
>   	struct iio_cb_buffer *cb_buff = buffer_to_cb_buffer(buffer);
> +
> +	if (!cb_buff->cb)
> +		return 0;
> +
I think it makes more sense to check this once when the buffer is 
registered instead of every time we want to call the function.
Lars-Peter Clausen Nov. 12, 2020, 4:20 p.m. UTC | #2
On 11/12/20 5:15 PM, Lars-Peter Clausen wrote:
> On 11/12/20 4:13 PM, Nuno Sá wrote:
>> Make sure that a callback is actually present before trying to call
>> it...
>>
>> Signed-off-by: Nuno Sá <nuno.sa@analog.com>
>> ---
>>   drivers/iio/buffer/industrialio-buffer-cb.c | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/drivers/iio/buffer/industrialio-buffer-cb.c 
>> b/drivers/iio/buffer/industrialio-buffer-cb.c
>> index 47c96f7f4976..b4385f59399d 100644
>> --- a/drivers/iio/buffer/industrialio-buffer-cb.c
>> +++ b/drivers/iio/buffer/industrialio-buffer-cb.c
>> @@ -27,6 +27,10 @@ static struct iio_cb_buffer 
>> *buffer_to_cb_buffer(struct iio_buffer *buffer)
>>   static int iio_buffer_cb_store_to(struct iio_buffer *buffer, const 
>> void *data)
>>   {
>>       struct iio_cb_buffer *cb_buff = buffer_to_cb_buffer(buffer);
>> +
>> +    if (!cb_buff->cb)
>> +        return 0;
>> +
> I think it makes more sense to check this once when the buffer is 
> registered instead of every time we want to call the function.

Sorry, should have read the cover letter more carefully. What you write 
there makes sense.
diff mbox series

Patch

diff --git a/drivers/iio/buffer/industrialio-buffer-cb.c b/drivers/iio/buffer/industrialio-buffer-cb.c
index 47c96f7f4976..b4385f59399d 100644
--- a/drivers/iio/buffer/industrialio-buffer-cb.c
+++ b/drivers/iio/buffer/industrialio-buffer-cb.c
@@ -27,6 +27,10 @@  static struct iio_cb_buffer *buffer_to_cb_buffer(struct iio_buffer *buffer)
 static int iio_buffer_cb_store_to(struct iio_buffer *buffer, const void *data)
 {
 	struct iio_cb_buffer *cb_buff = buffer_to_cb_buffer(buffer);
+
+	if (!cb_buff->cb)
+		return 0;
+
 	return cb_buff->cb(data, cb_buff->private);
 }