mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jijie Shao <shaojijie@huawei.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: <shaojijie@huawei.com>, <davem@davemloft.net>,
	<edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>,
	<andrew+netdev@lunn.ch>, <horms@kernel.org>,
	<shenjian15@huawei.com>, <wangpeiyang1@huawei.com>,
	<liuyonglong@huawei.com>, <chenhao418@huawei.com>,
	<sudongming1@huawei.com>, <xujunsheng@huawei.com>,
	<shiyongbang@huawei.com>, <libaihan@huawei.com>,
	<jonathan.cameron@huawei.com>,
	<shameerali.kolothum.thodi@huawei.com>, <salil.mehta@huawei.com>,
	<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<hkelam@marvell.com>
Subject: Re: [PATCH V5 net-next 1/8] debugfs: Add debugfs_create_devm_dir() helper
Date: Mon, 9 Dec 2024 18:33:54 +0800	[thread overview]
Message-ID: <bb464691-06c0-4842-8e4f-27cf368b363f@huawei.com> (raw)
In-Reply-To: <2024120925-dreamt-immorally-f9f8@gregkh>


on 2024/12/9 14:31, Greg KH wrote:
> On Mon, Dec 09, 2024 at 09:02:10AM +0800, Jijie Shao wrote:
>> on 2024/12/6 19:40, Greg KH wrote:
>>> On Fri, Dec 06, 2024 at 07:16:22PM +0800, Jijie Shao wrote:
>>>> Add debugfs_create_devm_dir() helper
>>>>
>>>> Signed-off-by: Jijie Shao <shaojijie@huawei.com>
>>>> ---
>>>>    fs/debugfs/inode.c      | 36 ++++++++++++++++++++++++++++++++++++
>>>>    include/linux/debugfs.h | 10 ++++++++++
>>>>    2 files changed, 46 insertions(+)
>>>>
>>>> diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
>>>> index 38a9c7eb97e6..f682c4952a27 100644
>>>> --- a/fs/debugfs/inode.c
>>>> +++ b/fs/debugfs/inode.c
>>>> @@ -610,6 +610,42 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
>>>>    }
>>>>    EXPORT_SYMBOL_GPL(debugfs_create_dir);
>>>> +static void debugfs_remove_devm(void *dentry_rwa)
>>>> +{
>>>> +	struct dentry *dentry = dentry_rwa;
>>>> +
>>>> +	debugfs_remove(dentry);
>>>> +}
>>>> +
>>>> +/**
>>>> + * debugfs_create_devm_dir - Managed debugfs_create_dir()
>>>> + * @dev: Device that owns the action
>>>> + * @name: a pointer to a string containing the name of the directory to
>>>> + *        create.
>>>> + * @parent: a pointer to the parent dentry for this file.  This should be a
>>>> + *          directory dentry if set.  If this parameter is NULL, then the
>>>> + *          directory will be created in the root of the debugfs filesystem.
>>>> + * Managed debugfs_create_dir(). dentry will automatically be remove on
>>>> + * driver detach.
>>>> + */
>>>> +struct dentry *debugfs_create_devm_dir(struct device *dev, const char *name,
>>>> +				       struct dentry *parent)
>>>> +{
>>>> +	struct dentry *dentry;
>>>> +	int ret;
>>>> +
>>>> +	dentry = debugfs_create_dir(name, parent);
>>>> +	if (IS_ERR(dentry))
>>>> +		return dentry;
>>>> +
>>>> +	ret = devm_add_action_or_reset(dev, debugfs_remove_devm, dentry);
>>>> +	if (ret)
>>>> +		ERR_PTR(ret);
>>> You don't clean up the directory you created if this failed?  Why not?
>> Don't need to clean up.
>> in devm_add_action_or_reset(), if failed, will call action: debugfs_remove_devm(),
>> So, not clean up again.
>>
>> #define devm_add_action_or_reset(dev, action, data) \
>> 	__devm_add_action_or_reset(dev, action, data, #action)
>>
>> static inline int __devm_add_action_or_reset(struct device *dev, void (*action)(void *),
>> 					     void *data, const char *name)
>> {
>> 	int ret;
>>
>> 	ret = __devm_add_action(dev, action, data, name);
>> 	if (ret)
>> 		action(data);
>>
>> 	return ret;
>> }
>>
>> But there's a problem with this, I missed return.
>> I will add return in v6.
> As this did not even compile, how did you test any of this?
>
> I'm now loath to add this at all, please let's just keep this "open
> coded" in your driver for now until there are multiple users that need
> this and then convert them all to use the function when you add it.
>
> thanks,
>
> greg k-h

I've tested and it's ok,

But, there is a warning(warn_unused_result)..
My test command does not check warning other than the hibmcge driver.
This was caused by my carelessness. I'm very sorry.

I've looked at other driver codes, and quite a few others have similar codes.
As you suggest, this patchset still uses open code in next version.
In the future, I will try to send a new independent patchset to introduce it.

Thanks,
Jijie Shao


  reply	other threads:[~2024-12-09 10:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-06 11:16 [PATCH V5 net-next 0/8] Support some features for the HIBMCGE driver Jijie Shao
2024-12-06 11:16 ` [PATCH V5 net-next 1/8] debugfs: Add debugfs_create_devm_dir() helper Jijie Shao
2024-12-06 11:40   ` Greg KH
2024-12-09  1:02     ` Jijie Shao
2024-12-09  6:31       ` Greg KH
2024-12-09 10:33         ` Jijie Shao [this message]
2024-12-06 14:57   ` kernel test robot
2024-12-06 16:50   ` kernel test robot
2024-12-06 11:16 ` [PATCH V5 net-next 2/8] net: hibmcge: Add debugfs supported in this module Jijie Shao
2024-12-06 11:16 ` [PATCH V5 net-next 3/8] net: hibmcge: Add irq_info file to debugfs Jijie Shao
2024-12-06 11:16 ` [PATCH V5 net-next 4/8] net: hibmcge: Add unicast frame filter supported in this module Jijie Shao
2024-12-06 11:16 ` [PATCH V5 net-next 5/8] net: hibmcge: Add register dump " Jijie Shao
2024-12-06 11:16 ` [PATCH V5 net-next 6/8] net: hibmcge: Add pauseparam " Jijie Shao
2024-12-06 11:16 ` [PATCH V5 net-next 7/8] net: hibmcge: Add reset " Jijie Shao
2024-12-06 11:16 ` [PATCH V5 net-next 8/8] net: hibmcge: Add nway_reset " Jijie Shao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bb464691-06c0-4842-8e4f-27cf368b363f@huawei.com \
    --to=shaojijie@huawei.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=chenhao418@huawei.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hkelam@marvell.com \
    --cc=horms@kernel.org \
    --cc=jonathan.cameron@huawei.com \
    --cc=kuba@kernel.org \
    --cc=libaihan@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuyonglong@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=salil.mehta@huawei.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=shenjian15@huawei.com \
    --cc=shiyongbang@huawei.com \
    --cc=sudongming1@huawei.com \
    --cc=wangpeiyang1@huawei.com \
    --cc=xujunsheng@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®