Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp530614pxj; Thu, 13 May 2021 10:29:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywK723OvQdoJH5DhYUgL9F4/7KjaujEhVfbrNQjtkWHPN+/QsTEOV0N0zR6DHSky3UavfF X-Received: by 2002:a17:906:9444:: with SMTP id z4mr44753610ejx.330.1620926988542; Thu, 13 May 2021 10:29:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620926988; cv=none; d=google.com; s=arc-20160816; b=nrqmppsx8uPQnDfKd97s7NtRc2ILWKoL8oFMk6DS5f+ztn77MA0NjqR5YqTp9gHlrg oVRY5Qby436cKXw0F8j7Jm27kfheu5HjCBO58dW1F6KGXmdrU2xOtsMaqa3amxYqooUD kmTcLzPp/yGC8Hfe744QnSBt/Zz97tKROAufW241sxQp5aQs37eslMJiMFCOaBusplNz yg3SbUk0/kPFbxjIKrtXxcmIEUWdeKV5bG65PyzRVvCoMIqlguoFJw0oCwSNHX32UIzo y3zhu36cJ9Vf9sWu7pBjIAI0MKogzcbsQT8lZ65aZkzUrqLkcfXe9oZ4dLteeJ9XGHC1 HDNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=mrNjY7B7RhMGjzcyAALH6BMidIjG9PYGm2iFaBxLPWU=; b=TgPkJEhdzsAPnHjqvWeq/kwi3EUU4IiW3JaY8hSiVi1Ate5GPp6iwlGtCz5fbxUR6/ HJAWxgiMtbnPKMTNzQ9zQgH8lUKXVHQF5IarI01jYF2q2clJDe7v0qAZZByAjU1/WTTY b6QJ9qk7rAXuJEj82yWgSG7Bt8iZbDAY+zJxYjg1/IqX6skCn1gqhqaI0qvRcHX4Yhd3 QqjZ1dM8DEzJ0CkvekaVNO/WXFBPLeMpj+OHv4WfDB0PwQz+tnU8okDvVS0yuyAYudrZ fqbOE2SewJGca1sp3ob51k/ujVRgrqsGg94fqTrvTipNkjhQN4rJ5XiVHGDvWtdH7IHK XN1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gw0qVY+M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rs3si3467789ejb.501.2021.05.13.10.29.24; Thu, 13 May 2021 10:29:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gw0qVY+M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230383AbhEMR3Q (ORCPT + 99 others); Thu, 13 May 2021 13:29:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229877AbhEMR3O (ORCPT ); Thu, 13 May 2021 13:29:14 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6ADCEC061574 for ; Thu, 13 May 2021 10:28:04 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id e11so21124741ljn.13 for ; Thu, 13 May 2021 10:28:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mrNjY7B7RhMGjzcyAALH6BMidIjG9PYGm2iFaBxLPWU=; b=gw0qVY+MdqpAKcHf8Ifw79XmeEWUl1BMliSmPuZAMcxx3qHwcPr2l4Naqtfy/qgU6/ 0i1zUFcfG3Hm1Ccf7Gf+DPZ+hax1qb0TfKega+NTTAtqF11dIYbVBy/eSZ68NakuZxVS 40LvXCU6UXJ4zswnL0t1ZUL8m26d508CbbdhlPcpaRfsWUw/1IKQMWuTJRL7ao8DtrEI z0ggVgdAUrNv7OvDwpGNVwI6V1pUNj4qFaQ9dvfCWfI4Jf6K34hyGQQSEd5SBCdsDPGu DeJDcJFlQyV0XsPULu6FyOXX4xG4hfd7jFIboqy8+J+P1eKepbIPw5DDvaSh4OPMU6gg XtZw== 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=mrNjY7B7RhMGjzcyAALH6BMidIjG9PYGm2iFaBxLPWU=; b=MpKDGhKGMFBO78DHBUi3rz+5NAKGgOiM0VZ83rDLwA7+ywsVjczv8FAzNR3WvCjbgQ ZCI9GLD1NpZu7gNdR441pWpFS4PeiZZyjVb4qD2cMabCsT/zHGyzywnwjooXRF8TVukP 4Zljcxu6snQ7AXZxCCFz8+7pj7VFQme/s7b4XYwAsl77enAuwca6iWEPNlFZ5c+7JxOG v2oj6pC4egW9+yxOrwlCJxVrHi1z8O4wRFvhcAq1xmj346tzlvB5n1SUO8ANOTmK4jr1 w1Bq9kYs0En5rALp1LBzf1v+M2ftZ/085ub0388LOmgKQDA6HyV728D63ncJSV8YR4xm fx/Q== X-Gm-Message-State: AOAM533l7HuuiWA6xiZljEKaiflCTLrf0YfQAeJqZ3JwhbJO5ST09PzN G7dacu9GdeKAo9wZVp5WWsK933S2NtokG6FAalzt1oE+PSrP+g== X-Received: by 2002:a2e:9b8c:: with SMTP id z12mr35297361lji.267.1620926882716; Thu, 13 May 2021 10:28:02 -0700 (PDT) MIME-Version: 1.0 References: <20210512213457.1310774-1-rajatja@google.com> In-Reply-To: From: Rajat Jain Date: Thu, 13 May 2021 10:27:26 -0700 Message-ID: Subject: Re: [PATCH v3 1/2] driver core: Move the "removable" attribute from USB to core To: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" , Bjorn Helgaas , Alan Stern , Linux Kernel Mailing List , linux-pci , "open list:ULTRA-WIDEBAND (UWB) SUBSYSTEM:" , Bjorn Helgaas , Oliver Neukum , David Laight , =?UTF-8?Q?Krzysztof_Wilczy=C5=84ski?= , Rajat Jain , Jesse Barnes , Dmitry Torokhov Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 13, 2021 at 9:40 AM Greg Kroah-Hartman wrote: > > On Thu, May 13, 2021 at 09:26:26AM -0700, Rajat Jain wrote: > > > > static ssize_t ltm_capable_show(struct device *dev, > > > > struct device_attribute *attr, char *buf) > > > > { > > > > @@ -828,7 +805,6 @@ static struct attribute *dev_attrs[] = { > > > > &dev_attr_avoid_reset_quirk.attr, > > > > &dev_attr_authorized.attr, > > > > &dev_attr_remove.attr, > > > > - &dev_attr_removable.attr, > > > > &dev_attr_ltm_capable.attr, > > > > #ifdef CONFIG_OF > > > > &dev_attr_devspec.attr, > > > > diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c > > > > index 62368c4ed37a..ce18e84528cf 100644 > > > > --- a/drivers/usb/core/usb.c > > > > +++ b/drivers/usb/core/usb.c > > > > @@ -569,6 +569,7 @@ struct device_type usb_device_type = { > > > > #ifdef CONFIG_PM > > > > .pm = &usb_device_pm_ops, > > > > #endif > > > > + .supports_removable = true, > > > > }; > > > > > > > > > > > > diff --git a/include/linux/device.h b/include/linux/device.h > > > > index 38a2071cf776..7e87ab048307 100644 > > > > --- a/include/linux/device.h > > > > +++ b/include/linux/device.h > > > > @@ -93,6 +93,8 @@ struct device_type { > > > > void (*release)(struct device *dev); > > > > > > > > const struct dev_pm_ops *pm; > > > > + > > > > + bool supports_removable:1; /* subsystem can classify removable/fixed */ > > > > > > Why isn't this a bus type? Shouldn't it go there and not in the device > > > type? > > > > Please see below. > > > > > > > > > }; > > > > > > > > /* interface for exporting device attributes */ > > > > @@ -350,6 +352,19 @@ enum dl_dev_state { > > > > DL_DEV_UNBINDING, > > > > }; > > > > > > > > +/** > > > > + * enum device_removable - Whether the device is removable. The criteria for a > > > > + * device to be classified as removable is determined by its subsystem or bus. > > > > + * @DEVICE_REMOVABLE_UNKNOWN: Device location is Unknown (default). > > > > + * @DEVICE_REMOVABLE: Device is removable by the user. > > > > + * @DEVICE_FIXED: Device is not removable by the user. > > > > + */ > > > > +enum device_removable { > > > > + DEVICE_REMOVABLE_UNKNOWN = 0, > > > > + DEVICE_REMOVABLE, > > > > + DEVICE_FIXED, > > > > +}; > > > > + > > > > /** > > > > * struct dev_links_info - Device data related to device links. > > > > * @suppliers: List of links to supplier devices. > > > > @@ -431,6 +446,9 @@ struct dev_links_info { > > > > * device (i.e. the bus driver that discovered the device). > > > > * @iommu_group: IOMMU group the device belongs to. > > > > * @iommu: Per device generic IOMMU runtime data > > > > + * @removable: Whether the device can be removed from the system. This > > > > + * should be set by the subsystem / bus driver that discovered > > > > + * the device. > > > > * > > > > * @offline_disabled: If set, the device is permanently online. > > > > * @offline: Set after successful invocation of bus type's .offline(). > > > > @@ -544,6 +562,8 @@ struct device { > > > > struct iommu_group *iommu_group; > > > > struct dev_iommu *iommu; > > > > > > > > + enum device_removable removable; > > > > + > > > > bool offline_disabled:1; > > > > bool offline:1; > > > > bool of_node_reused:1; > > > > @@ -782,6 +802,18 @@ static inline bool dev_has_sync_state(struct device *dev) > > > > return false; > > > > } > > > > > > > > +static inline void dev_set_removable(struct device *dev, > > > > + enum device_removable removable) > > > > +{ > > > > + dev->removable = removable; > > > > +} > > > > + > > > > +static inline bool dev_is_removable(struct device *dev) > > > > +{ > > > > + return dev && dev->type && dev->type->supports_removable > > > > + && dev->removable == DEVICE_REMOVABLE; > > > > > > Again, shouldn't this be a bus type, and not a device type? > > > > > > Where are you going to have devices of different types on a bus that do, > > > or do not, allow this attribute? > > > > USB. Presently, both the usb_device_type and usb_if_device_type sit on > > the usb_bus_type but "removable" only applies to usb_device_type (the > > attribute shows up only under usb_devices and not under > > usb_interfaces). > > Ah. Messy. > > Then should this be a per-device value and don't worry about the type at > all? You have a field in the device already, why not make it: > > enum device_removable { > DEVICE_REMOVABLE_NOT_SUPPORTED = 0, /* must be 0 */ > DEVICE_REMOVABLE_UNKNOWN, > DEVICE_REMOVABLE, > DEVICE_FIXED, > }; > > And then only show the file if a device does NOT have the value set to > DEVICE_REMOVABLE_NOT_SUPPORTED? > > If a bus/subsystem/whatever wants the device to have a sysfs file and > value there, then it needs to set it to anything other than 0 and it > will be created? Ack, will do. Thanks, Rajat > > That gets you out of the device bus/type mess and it is localized to > only the device itself, allowing for any device to do this? Should make > the logic everywhere a bit simpler as well. > > thanks, > > greg k-h