mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] relay: avoid relay_open_buf inproperly fails in buffer-only mode
@ 2024-02-20 10:58 Philo Lu
  2024-03-15  2:39 ` zhangzhengming
  0 siblings, 1 reply; 3+ messages in thread
From: Philo Lu @ 2024-02-20 10:58 UTC (permalink / raw)
  To: linux-kernel
  Cc: akpm, zhou.kete, zhao_lei1, nabijaczleweli, kunyu,
	zhang.zhengming, gregkh, xuanzhuo, dust.li, alibuda, guwen,
	hengqi

In buffer-only mode, relay_open(NULL, NULL, ...) is used to create the
buffer first, where chan->has_base_filename is not set. Though we still
need to call chan->cb->create_buf_file in relay_open_buf() to retrieve
global info for global buffer, the create_buf_file callback should
return NULL. However, with IS_ERR_OR_NULL() checking, relay_open fails
because the returned dentry == NULL.

This patch remove the IS_ERR_OR_NULL() for compatibility and update the
comment to explain the behavior.

Here is a create_buf_file callback example after fix:
```
struct dentry *my_create_buf_file(const char *filename,
            struct dentry *parent, umode_t mode,
            struct rchan_buf *buf, int *is_global)
{
    if (!filename)
        return NULL;

    return debugfs_create_file(filename, mode, parent, buf,
                &relay_file_operations);
}

relay_cb.create_buf_file = my_create_buf_file
relay_chan = relay_open(NULL, NULL,
                    subbuf_size, subbuf_num,
                    &relay_cb, NULL);
relay_late_setup_files(relay_chan, filename, parent);
```

But before fix, the callback must be something like:
```
struct dentry *my_create_buf_file(const char *filename,
            struct dentry *parent, umode_t mode,
            struct rchan_buf *buf, int *is_global)
{
    if (!filename)
        return ERR_PTR(1); // a valid ptr is necessary for relay_open

    return debugfs_create_file(filename, mode, parent, buf,
                &relay_file_operations);
}
```

Fixes: 2c1cf00eeacb ("relay: check return of create_buf_file() properly")
Signed-off-by: Philo Lu <lulie@linux.alibaba.com>
---
 kernel/relay.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/kernel/relay.c b/kernel/relay.c
index a8e90e98bf2c..0d8b8325530a 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -391,12 +391,13 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan, unsigned int cpu)
 			goto free_buf;
 		relay_set_buf_dentry(buf, dentry);
 	} else {
-		/* Only retrieve global info, nothing more, nothing less */
+		/* In buffer-only mode, relay_open_buf is called with
+		 * filename=NULL, but create_buf_file is still needed to
+		 * retrieve is_global info. So dentry should be NULL here.
+		 */
 		dentry = chan->cb->create_buf_file(NULL, NULL,
 						   S_IRUSR, buf,
 						   &chan->is_global);
-		if (IS_ERR_OR_NULL(dentry))
-			goto free_buf;
 	}
 
  	buf->cpu = cpu;
-- 
2.32.0.3.g01195cf9f


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] relay: avoid relay_open_buf inproperly fails in buffer-only mode
  2024-02-20 10:58 [PATCH] relay: avoid relay_open_buf inproperly fails in buffer-only mode Philo Lu
@ 2024-03-15  2:39 ` zhangzhengming
  2024-03-15  3:22   ` Philo Lu
  0 siblings, 1 reply; 3+ messages in thread
From: zhangzhengming @ 2024-03-15  2:39 UTC (permalink / raw)
  To: lulie
  Cc: akpm, alibuda, dust.li, gregkh, guwen, hengqi, kunyu,
	linux-kernel, nabijaczleweli, xuanzhuo, zhang.zhengming,
	zhao_lei1, zhou.kete

> diff --git a/kernel/relay.c b/kernel/relay.c
> index a8e90e98bf2c..0d8b8325530a 100644
> --- a/kernel/relay.c
> +++ b/kernel/relay.c
> @@ -391,12 +391,13 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan, unsigned int cpu)
>  			goto free_buf;
>  		relay_set_buf_dentry(buf, dentry);
>  	} else {
> -		/* Only retrieve global info, nothing more, nothing less */
> +		/* In buffer-only mode, relay_open_buf is called with
> +		 * filename=NULL, but create_buf_file is still needed to
> +		 * retrieve is_global info. So dentry should be NULL here.
> +		 */
>  		dentry = chan->cb->create_buf_file(NULL, NULL,
>  						   S_IRUSR, buf,
>  						   &chan->is_global);
> -		if (IS_ERR_OR_NULL(dentry))
> -			goto free_buf;
>  	}
>  
>   	buf->cpu = cpu;
I suggest replacing IS_ERR_OR_NULL with IS_ERR instead of removing it due to the possibility of create_buf_file callback returning an error.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] relay: avoid relay_open_buf inproperly fails in buffer-only mode
  2024-03-15  2:39 ` zhangzhengming
@ 2024-03-15  3:22   ` Philo Lu
  0 siblings, 0 replies; 3+ messages in thread
From: Philo Lu @ 2024-03-15  3:22 UTC (permalink / raw)
  To: zhangzhengming
  Cc: akpm, alibuda, dust.li, gregkh, guwen, hengqi, kunyu,
	linux-kernel, nabijaczleweli, xuanzhuo, zhao_lei1, zhou.kete



On 2024/3/15 10:39, zhangzhengming wrote:
>> diff --git a/kernel/relay.c b/kernel/relay.c
>> index a8e90e98bf2c..0d8b8325530a 100644
>> --- a/kernel/relay.c
>> +++ b/kernel/relay.c
>> @@ -391,12 +391,13 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan, unsigned int cpu)
>>   			goto free_buf;
>>   		relay_set_buf_dentry(buf, dentry);
>>   	} else {
>> -		/* Only retrieve global info, nothing more, nothing less */
>> +		/* In buffer-only mode, relay_open_buf is called with
>> +		 * filename=NULL, but create_buf_file is still needed to
>> +		 * retrieve is_global info. So dentry should be NULL here.
>> +		 */
>>   		dentry = chan->cb->create_buf_file(NULL, NULL,
>>   						   S_IRUSR, buf,
>>   						   &chan->is_global);
>> -		if (IS_ERR_OR_NULL(dentry))
>> -			goto free_buf;
>>   	}
>>   
>>    	buf->cpu = cpu;
> I suggest replacing IS_ERR_OR_NULL with IS_ERR instead of removing it due to the possibility of create_buf_file callback returning an error.
> 

This would be fine. AFAICT the return value here is un-important. So 
reverting to `WARN_ON(dentry)` maybe another choice.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-15  3:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-20 10:58 [PATCH] relay: avoid relay_open_buf inproperly fails in buffer-only mode Philo Lu
2024-03-15  2:39 ` zhangzhengming
2024-03-15  3:22   ` Philo Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®