Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2953367imu; Fri, 18 Jan 2019 02:09:29 -0800 (PST) X-Google-Smtp-Source: ALg8bN7rHyhMUMyvEXQbXHwKgw73ez9mG4cA7l79OkbDo4DGJjiBXYNM3olQ9YZDFFboGtkibdad X-Received: by 2002:a17:902:e002:: with SMTP id ca2mr18829333plb.103.1547806169535; Fri, 18 Jan 2019 02:09:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547806169; cv=none; d=google.com; s=arc-20160816; b=dN59ojZtFCgcvCKCq89PgVwqL8nhJLAEp+cwk41APNHn7rqomGxm2v/vf6QeQ1H1VD hV2fUsPkB9lPxuxeTdzV9HqP1cIYDeh+LWHow+uqhw+2J33Wt2dJyvs7xNYCE24pRB4e PdM5NQvzAWi0Oi6WEpwGFLN58H6zqJ39gjo6jq7zrIgs5dJ/8baea00Qn6LrIz7/M3yD rmrnZ2n66Jx9Ikkn4otcdDYNe9ElkUAyrp+XX9yzc0ozJ4yWdJwQTW9yrNhRsNINz0py qPo929qB3g9Ok+M/zxbbauAQ0jO2USn0F+JfkvOWvYaQqFf5MtJ1mr/0TKhxLHNeLmr0 JNhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=qjSsv1H165uHCWRa88bMMW0DHBNTYFspTFebZSHgK4s=; b=v702qeUODKg4Pufrf2YHsSp7Fxwp9dbhVup3AyfJ29w0DbRYIdPfHIYkkAMIWf07LC jgaZMKXz9hs+y1muUFN8XUU1x8HKVIaXO3uktSzPnmvGj5/oAUeTLiOi6ujpe2MCNNHb hpGO43qyJXc3Sl66q5xtLd8BVjK4EiXG5mN7IF7roQn/4HWZQwWqG2F1zXC/P+aZidtX 3YMbvydIHAq08/aYeirOIeS6S+JsZJdQh+d1jy9gRntq2jHo90erKG0je94qX9Xv9C2X xHFrPj3WOV/7HDvC3nxeBv1ote58Ot379SaFM8twJK97mlX/vuwnAUBEzFvVk1kAkNNp WNBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v4si4202243pfm.71.2019.01.18.02.09.13; Fri, 18 Jan 2019 02:09:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727230AbfARKGh (ORCPT + 99 others); Fri, 18 Jan 2019 05:06:37 -0500 Received: from mail-oi1-f196.google.com ([209.85.167.196]:39313 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726334AbfARKGh (ORCPT ); Fri, 18 Jan 2019 05:06:37 -0500 Received: by mail-oi1-f196.google.com with SMTP id i6so8551698oia.6 for ; Fri, 18 Jan 2019 02:06:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qjSsv1H165uHCWRa88bMMW0DHBNTYFspTFebZSHgK4s=; b=Excv/ANm3lXKBIVbPdbPxmCeouFrQ8x21uHF4UJcVT68lH/iUtYQbkFOqZyXwCOIa+ 3+tnW4E3uRIzKL+LS/5pQ4McvEVVSBziuiQgqaCa3E8kVWij41MGuQpcxmR4uaSBupBt pXQwKZhgvdVdSGcRhYZ4jIJep2n3CbvxPG06eMH8r6fDdA9y+lWyMwHvv8H/xXsSv1Ww bE1pg8+diLrJIAhj+kD0IqQPRieATuVYM+A0TOrltinWPfSWToNlm98tPpnIdI1rvJNL MaMdpQHIDMeBmorT2nxqQXUBMy8UHJ0chiiUXUC4znvJfdY95nnxRyf4ZgVq4gQbl03s tcww== X-Gm-Message-State: AJcUukcacbY60nP080ubG/26q9JNbqLnA+eSPY6pu4l/bRQ/2MxQEEMV wUpBCodGqwLtqiwXYnsxeH69XWU++5dSBgx48FO6zQ== X-Received: by 2002:aca:e715:: with SMTP id e21mr205026oih.76.1547805995871; Fri, 18 Jan 2019 02:06:35 -0800 (PST) MIME-Version: 1.0 References: <20190117055719.6161-1-richardw.yang@linux.intel.com> <20190118023459.9972-1-richardw.yang@linux.intel.com> In-Reply-To: <20190118023459.9972-1-richardw.yang@linux.intel.com> From: "Rafael J. Wysocki" Date: Fri, 18 Jan 2019 11:06:23 +0100 Message-ID: Subject: Re: [PATCH v2] driver core: move device->knode_class to device_private To: Wei Yang Cc: Linux Kernel Mailing List , Greg Kroah-Hartman , "Rafael J. Wysocki" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 18, 2019 at 3:35 AM Wei Yang wrote: > > As the description of struct device_private says, it stores data which > is private to driver core. And it already has similar fields like: > knode_parent, knode_driver, knode_driver and knode_bus. This look it is > more proper to put knode_class together with those fields to make it > private to driver core. > > This patch move device->knode_class to device_private to make it comply > with code convention. > > Signed-off-by: Wei Yang > > --- > v2: add a helper to get dev from klist_class Looks better now. Reviewed-by: Rafael J. Wysocki > --- > drivers/base/base.h | 4 ++++ > drivers/base/class.c | 14 ++++++++++---- > drivers/base/core.c | 4 ++-- > include/linux/device.h | 1 - > 4 files changed, 16 insertions(+), 7 deletions(-) > > diff --git a/drivers/base/base.h b/drivers/base/base.h > index 7a419a7a6235..37329a668935 100644 > --- a/drivers/base/base.h > +++ b/drivers/base/base.h > @@ -60,6 +60,7 @@ struct driver_private { > * @knode_parent - node in sibling list > * @knode_driver - node in driver list > * @knode_bus - node in bus list > + * @knode_class - node in class list > * @deferred_probe - entry in deferred_probe_list which is used to retry the > * binding of drivers which were unable to get all the resources needed by > * the device; typically because it depends on another driver getting > @@ -74,6 +75,7 @@ struct device_private { > struct klist_node knode_parent; > struct klist_node knode_driver; > struct klist_node knode_bus; > + struct klist_node knode_class; > struct list_head deferred_probe; > struct device *device; > }; > @@ -83,6 +85,8 @@ struct device_private { > container_of(obj, struct device_private, knode_driver) > #define to_device_private_bus(obj) \ > container_of(obj, struct device_private, knode_bus) > +#define to_device_private_class(obj) \ > + container_of(obj, struct device_private, knode_class) > > /* initialisation functions */ > extern int devices_init(void); > diff --git a/drivers/base/class.c b/drivers/base/class.c > index 54def4e02f00..d8a6a5864c2e 100644 > --- a/drivers/base/class.c > +++ b/drivers/base/class.c > @@ -117,16 +117,22 @@ static void class_put(struct class *cls) > kset_put(&cls->p->subsys); > } > > +static struct device *klist_class_to_dev(struct klist_node *n) > +{ > + struct device_private *p = to_device_private_class(n); > + return p->device; > +} > + > static void klist_class_dev_get(struct klist_node *n) > { > - struct device *dev = container_of(n, struct device, knode_class); > + struct device *dev = klist_class_to_dev(n); > > get_device(dev); > } > > static void klist_class_dev_put(struct klist_node *n) > { > - struct device *dev = container_of(n, struct device, knode_class); > + struct device *dev = klist_class_to_dev(n); > > put_device(dev); > } > @@ -277,7 +283,7 @@ void class_dev_iter_init(struct class_dev_iter *iter, struct class *class, > struct klist_node *start_knode = NULL; > > if (start) > - start_knode = &start->knode_class; > + start_knode = &start->p->knode_class; > klist_iter_init_node(&class->p->klist_devices, &iter->ki, start_knode); > iter->type = type; > } > @@ -304,7 +310,7 @@ struct device *class_dev_iter_next(struct class_dev_iter *iter) > knode = klist_next(&iter->ki); > if (!knode) > return NULL; > - dev = container_of(knode, struct device, knode_class); > + dev = klist_class_to_dev(knode); > if (!iter->type || iter->type == dev->type) > return dev; > } > diff --git a/drivers/base/core.c b/drivers/base/core.c > index 04bbcd779e11..a624d27d11c0 100644 > --- a/drivers/base/core.c > +++ b/drivers/base/core.c > @@ -1932,7 +1932,7 @@ int device_add(struct device *dev) > if (dev->class) { > mutex_lock(&dev->class->p->mutex); > /* tie the class to the device */ > - klist_add_tail(&dev->knode_class, > + klist_add_tail(&dev->p->knode_class, > &dev->class->p->klist_devices); > > /* notify any interfaces that the device is here */ > @@ -2069,7 +2069,7 @@ void device_del(struct device *dev) > if (class_intf->remove_dev) > class_intf->remove_dev(dev, class_intf); > /* remove the device from the class list */ > - klist_del(&dev->knode_class); > + klist_del(&dev->p->knode_class); > mutex_unlock(&dev->class->p->mutex); > } > device_remove_file(dev, &dev_attr_uevent); > diff --git a/include/linux/device.h b/include/linux/device.h > index 1b25c7a43f4c..040e97669f94 100644 > --- a/include/linux/device.h > +++ b/include/linux/device.h > @@ -1035,7 +1035,6 @@ struct device { > spinlock_t devres_lock; > struct list_head devres_head; > > - struct klist_node knode_class; > struct class *class; > const struct attribute_group **groups; /* optional groups */ > > -- > 2.19.1 >