Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4884953pxj; Wed, 12 May 2021 15:39:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOvMCr0LStcBYUaHb20QX1rsL2I6RSL8Qcz1WLRUb0hTm7GbpLY01ZMr1cjMp0cuHkbRbO X-Received: by 2002:a17:906:4cc5:: with SMTP id q5mr40051339ejt.302.1620859185063; Wed, 12 May 2021 15:39:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620859185; cv=none; d=google.com; s=arc-20160816; b=zuWywrfW3nmaYnFfx6wxJmWRzerMy3M1byljld/o439uyefU/tzphHtXNMD+jIMi8B 3zkDyB6vKj7D6Z8cYH3oNRi1hTu3kZuVxUmQYJ3qbTRnqsB2Gv+jIkHo+tiLt+QzYff8 5BoS4OsTiazMc4YHrS0rero1ItrwmOwgt1PTyby0PdKYwCvacz//6QaIU1OD9CQqydKy guOxno8d1b448eO8zYH1S6EQcRt8woTyBVWMkZyEI8jhhvIC7cEe09FFRlgmokvr7VoN GEYOcOoq8G3LFq0dq2lxZYs7vPmmKVtat+oZv58cKS0FcWthK654Yt+hNWKYd6bykhOc Q/8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=zpuSVjKnd4Q/JUCBr5MA4TroaNsMxpRZib7L8EDA+Do=; b=hfPKnGiXhonZK+NTckAR0pCrGH6vsF/+5ZzPAOui+827BK8MXqoZAqIVCJHbeaIzZH WAKCYWW034LTb+tQgp1H6cpYR1vyQFiPSwQamrqtzZIv4mV2kS721HZYVR87+gzGUEeE PqANBjl/AN7szftfk9TynttJomzWsYB5jFiIxJkk7o9d8DsJGIl7NqSYcf/tzSruSg0l 9qgzKNZrFr9iOTEHJQzM+trNn3oABvJFKq1g+3kCVkebTRKEVIkQXsDP7mGjGH9wtVAi SD/PBDDfTPCJ2Oe6G8f0xbQQJeVnpIR8PSBrFa9BSh6VbFunyexWWXv20YLdO0aRxQyG JcJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=oEgvr7s+; 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 c5si868761eds.128.2021.05.12.15.39.21; Wed, 12 May 2021 15:39:45 -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=oEgvr7s+; 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 S1348783AbhELWiE (ORCPT + 99 others); Wed, 12 May 2021 18:38:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349210AbhELWas (ORCPT ); Wed, 12 May 2021 18:30:48 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4977FC06138F for ; Wed, 12 May 2021 15:28:16 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id y9so31576758ljn.6 for ; Wed, 12 May 2021 15:28:16 -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:content-transfer-encoding; bh=zpuSVjKnd4Q/JUCBr5MA4TroaNsMxpRZib7L8EDA+Do=; b=oEgvr7s+UdFc5aoOn13VA2zxM4ckiXTEvq4SxAi15WwW8XAawCwo2F81HFAUqmfQ93 Fyv5yrqModgAxJPHlwPJd5iTXR/oKCO2VBedmEZzz7ul7Ng4AlBauS7aRhvCzJS8XLSz zJRmETN9JJW6EcmPLqxFJRE0+6NKjkMQ/pQ/bZF77oZs7/zG+baxLHGjoTX8wBPfYBtD WSsgnlKfxaYV43ZV4uVv345w6yLHWVzMrNJU7+wxxeDub9R+Dv9bRm79EbrWc+Gvtxnk QSjtOXgPw7Llf6aBD8rcpwurQ9oUgU0YnWlyYT5/JoDqycE4zwsTxDAIi6t4tL00yMIX 4BSg== 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:content-transfer-encoding; bh=zpuSVjKnd4Q/JUCBr5MA4TroaNsMxpRZib7L8EDA+Do=; b=tO2a6SxRYVYUAvE8b9PCt/OCP9SntajtXhDSaUoCz9qUuqr9wAKQNfFQAwSk++KC5X 6JbFfIV/a+neFBRqtHl2Z67XNUKGm91qlUoxs0wUnSb2xI+DfEP+SywLpOZfg8TtxW/g GdnkAgMAYxgKqjGQMj2oxIonwEM7+6mWMSv7QQK4i2lt/soDQCUbGQgDTeYrqzewFf3s JLpl7lthl/fZWdZzYpM1EUYc8Xmnks5MOBFiC3B1KGvliWO4vZJ6EGF6b6SkawqK6/ix 1B8SSWWu7Os+32d3R4Q2UpVNiZMbFsJ5FfRheHsypaLX8WupHlTKPppb0vyGBN1R2HCK dH4w== X-Gm-Message-State: AOAM5324bVBXIc/YGWyLIzR47c7pQ4rnf0DEFUx4DdbUsuW2c0HbLUpp Z19xflVfuXtgwt3r6MNSemVqe2dARU1Ug4kFNtOQjA== X-Received: by 2002:a2e:9787:: with SMTP id y7mr30698250lji.65.1620858494395; Wed, 12 May 2021 15:28:14 -0700 (PDT) MIME-Version: 1.0 References: <20210424021631.1972022-1-rajatja@google.com> <20210512010049.GA89346@rocinante.localdomain> In-Reply-To: From: Rajat Jain Date: Wed, 12 May 2021 15:27:38 -0700 Message-ID: Subject: Re: [PATCH v2 1/2] driver core: Move the "removable" attribute from USB to core To: Rajat Jain Cc: =?UTF-8?Q?Krzysztof_Wilczy=C5=84ski?= , Greg Kroah-Hartman , "Rafael J. Wysocki" , Bjorn Helgaas , Alan Stern , Linux Kernel Mailing List , linux-pci , "open list:ULTRA-WIDEBAND (UWB) SUBSYSTEM:" , Bjorn Helgaas , Jesse Barnes , Dmitry Torokhov Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Posted a v3 of this patch here: https://lore.kernel.org/patchwork/patch/1428133/ On Tue, May 11, 2021 at 6:21 PM Rajat Jain wrote: > > Hi Krzysztof, > > Thanks a lot for your comments. Please see inline. > > On Tue, May 11, 2021 at 6:00 PM Krzysztof Wilczy=C5=84ski = wrote: > > > > Hi Rajat, > > > > I have few questions below, but to add in advance, I might be confusing > > the role that "type->supports_removable" and "dev->removable" plays > > here, and if so then I apologise. > > > > [...] > > > @@ -2504,8 +2523,16 @@ static int device_add_attrs(struct device *dev= ) > > > goto err_remove_dev_online; > > > } > > > > > > + if (type && type->supports_removable) { > > > + error =3D device_create_file(dev, &dev_attr_removable); > > > + if (error) > > > + goto err_remove_dev_waiting_for_supplier; > > > + } > > > + > > > return 0; > > > > Would a check for "dev->removable =3D=3D DEVICE_REMOVABLE" here be more > > appropriate? > > > > Unless you wanted to add sysfs objects when the device hints that it ha= s > > a notion of being removable even though it might be set to "unknown" or > > "fixed" (if that state is at all possible then), and in which case usin= g > > the dev_is_removable() helper would also not be an option since it does > > a more complex check internally. > > > > Technically, you could always add this sysfs object (similarly to what > > USB core did) as it would then show the correct state depending on > > "dev->removable". > > > > Also, I suppose, it's not possible for a device to have > > "supports_removable" set to true, but "removable" would be different > > than "DEVICE_REMOVABLE", correct? > > No, that is not true. > > device_type->supports_removable=3D1 indicates that the bus / subsystem > is capable of differentiating between removable and fixed devices. > It's essentially describing a capability of the bus / subsystem. This > flag needs to be true for a subsystem for any it's devices' > dev->removable field to be considered meaningful. > > OTOH, the dev->removable =3D> indicates the location of the device IF > device_type->supports location is true. Yes, it can be fixed / > removable / unknown (whatever the bus decides) if the > device_type->supports_location is true. > > One of my primary considerations was also that the existing UAPI for > the USB's "removable" attribute shouldn't be changed. Currently, it > exists for all USB devices, so I think the current code / check is OK. > > > > > [...] > > > +enum device_removable { > > > + DEVICE_REMOVABLE_UNKNOWN =3D 0, > > > + DEVICE_REMOVABLE, > > > + DEVICE_FIXED, > > > +}; > > > > I know this was moved from the USB core, but I personally find it > > a little bit awkward to read, would something like that be acceptable? > > > > enum device_removable { > > DEVICE_STATE_UNKNOWN =3D 0, > > DEVICE_STATE_REMOVABLE, > > DEVICE_STATE_FIXED, > > }; > > > > The addition of state to the name follows the removable_show() function > > where the local variable is called "state", and I think it makes sense > > to call this as such. What do you think? > > I think I made a mistake by using the "state" as the local variable > there. I will change it to "location". I'm happy to change the enums > above to DEVICE_LOCATION_REMOVABLE* etc if there is a wider consensus > on this. IMHO, the current shorter one also looks OK. > > > > > > +static inline bool dev_is_removable(struct device *dev) > > > +{ > > > + return dev && dev->type && dev->type->supports_removable > > > + && dev->removable =3D=3D DEVICE_REMOVABLE; > > > +} > > > > Similarly to my question about - would a simple check to see if > > "dev->removable" is set to "DEVICE_REMOVABLE" here be enough? > > No, as I mentioned above, the dev->removable field should be > considered meaningful only if device_type->supports_location is true. > So the check for supports_removable is needed here. > > Please feel free to send me more thoughts. > > Thanks & Best Regards, > > Rajat > > > > > > Krzysztof