public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH linux-next] nvme:Use the function kobj_to_dev()
@ 2022-08-11  1:29 cgel.zte
  2022-08-11  1:32 ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: cgel.zte @ 2022-08-11  1:29 UTC (permalink / raw)
  To: kbusch; +Cc: axboe, hch, sagi, linux-nvme, ye xingchen, Zeal Robot

From: ye xingchen <ye.xingchen@zte.com.cn>

Use kobj_to_dev() instead of open-coding it.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: ye xingchen <ye.xingchen@zte.com.cn>
---
 drivers/nvme/host/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index af367b22871b..6cbc03d6bb7d 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3432,7 +3432,7 @@ static struct attribute *nvme_ns_id_attrs[] = {
 static umode_t nvme_ns_id_attrs_are_visible(struct kobject *kobj,
 		struct attribute *a, int n)
 {
-	struct device *dev = container_of(kobj, struct device, kobj);
+	struct device *dev = kobj_to_dev(kobj);
 	struct nvme_ns_ids *ids = &dev_to_ns_head(dev)->ids;
 
 	if (a == &dev_attr_uuid.attr) {
@@ -3843,7 +3843,7 @@ static struct attribute *nvme_dev_attrs[] = {
 static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj,
 		struct attribute *a, int n)
 {
-	struct device *dev = container_of(kobj, struct device, kobj);
+	struct device *dev = kobj_to_dev(kobj);
 	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
 
 	if (a == &dev_attr_delete_controller.attr && !ctrl->ops->delete_ctrl)
-- 
2.25.1


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

* Re: [PATCH linux-next] nvme:Use the function kobj_to_dev()
  2022-08-11  1:29 [PATCH linux-next] nvme:Use the function kobj_to_dev() cgel.zte
@ 2022-08-11  1:32 ` Jens Axboe
  2022-08-11  5:59   ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2022-08-11  1:32 UTC (permalink / raw)
  To: cgel.zte, kbusch; +Cc: axboe, hch, sagi, linux-nvme, ye xingchen, Zeal Robot

On 8/10/22 7:29 PM, cgel.zte@gmail.com wrote:
> From: ye xingchen <ye.xingchen@zte.com.cn>
> 
> Use kobj_to_dev() instead of open-coding it.

This:

> -	struct device *dev = container_of(kobj, struct device, kobj);
> +	struct device *dev = kobj_to_dev(kobj);

just makes the code harder to read, imho. The original line, I can tell
what it does. The new line, I have to go look it up.

Is some tool suggesting these transformations? Because they look like a
bad idea to me, and we should fix that rather than make the code worse.

-- 
Jens Axboe



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

* Re: [PATCH linux-next] nvme:Use the function kobj_to_dev()
  2022-08-11  1:32 ` Jens Axboe
@ 2022-08-11  5:59   ` Christoph Hellwig
  0 siblings, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2022-08-11  5:59 UTC (permalink / raw)
  To: Jens Axboe
  Cc: cgel.zte, kbusch, axboe, hch, sagi, linux-nvme, ye xingchen,
	Zeal Robot

On Wed, Aug 10, 2022 at 07:32:40PM -0600, Jens Axboe wrote:
> > Use kobj_to_dev() instead of open-coding it.
> 
> This:
> 
> > -	struct device *dev = container_of(kobj, struct device, kobj);
> > +	struct device *dev = kobj_to_dev(kobj);
> 
> just makes the code harder to read, imho. The original line, I can tell
> what it does. The new line, I have to go look it up.

Exactly.

> Is some tool suggesting these transformations? Because they look like a
> bad idea to me, and we should fix that rather than make the code worse.

I keeps coming up again and again and one of the maintainers always
answers something like you just did.  Which suggests like someone or
something is unfortunately suggesting it.


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

end of thread, other threads:[~2022-08-11  6:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-11  1:29 [PATCH linux-next] nvme:Use the function kobj_to_dev() cgel.zte
2022-08-11  1:32 ` Jens Axboe
2022-08-11  5:59   ` Christoph Hellwig

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