Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp1372136ybj; Fri, 20 Sep 2019 09:23:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqzudRV8JVBJQXGdpjUMv/PzuwvBusafMhGeSUD5XgDQf5HExXw+e6w7yib5h2afOk3TN7cr X-Received: by 2002:a50:9a05:: with SMTP id o5mr23008232edb.44.1568996617851; Fri, 20 Sep 2019 09:23:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568996617; cv=none; d=google.com; s=arc-20160816; b=r6nHm0hN3vzyhyEjAxoDk4hYUfy0jlfikXgEogQSv40rm4XfXjdIqBVeNxDWjl79X6 TQDSa1Cw7rYmvKm6HjORFg84W5L6HPr9o3ttakm0+dGDOk2axQKqQEEwzBhlNvPoIwIc mIZyBF//QG0PbNJxud24P+U285Q7fjdDyCIW6V5nwzMjhH4qx1+kYOeUzWiaxLToAsjB +PCGXIQu/yv/NMRPploHAKfGg+wY9Te4NnzeTG6fmOK4HxLbyL9CNk7tlyBdB0pCol2z JnH03uAz1sYE+Z81G5ha3CZU23wCH4wanvyuGzDq4CCF11XqTb4RLXh3FkvHi1eC49+t kuDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature:dkim-signature; bh=3afxHgA00TkMxhqgQuTdvmm0klo8+6Oe4CbL9Tojbfo=; b=WSyq7NvG4yKLSkQkuYeNUCNEx+KT1i+RpHORJFH3JeT8xnfAjitDiCZyi/rQYzBOVh BySSeXNABUlwVNOKdtd8YLssJrpSx/3O1XLb85aec8cOnkPvaNqWllIxG48L1BcU29bx q10CEJHOdNKmzY4EMmzo0XhfrWJMf/h7GH9ldyeOfjmZf+p+YBTGuAHZ6ddo3+GfSvin G+MWGRx16WQW1y7TzAzM1aOdakMJpo03MYAj7ngHz92zyaePoJq/imIYWVmk1U55Caiz hL8GAlGdW/UvnE+OQ/z1axLreQcKbRqY5LjbKLkgnpNL8qUPDU61lWz2lvNOLn54RdkC lKDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b="d/MLPwEB"; dkim=pass header.i=@codeaurora.org header.s=default header.b=fcaT3HBO; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g3si1848628edj.220.2019.09.20.09.23.14; Fri, 20 Sep 2019 09:23:37 -0700 (PDT) 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; dkim=pass header.i=@codeaurora.org header.s=default header.b="d/MLPwEB"; dkim=pass header.i=@codeaurora.org header.s=default header.b=fcaT3HBO; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390882AbfISXja (ORCPT + 99 others); Thu, 19 Sep 2019 19:39:30 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:45508 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390217AbfISXja (ORCPT ); Thu, 19 Sep 2019 19:39:30 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 6751E6118C; Thu, 19 Sep 2019 23:39:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1568936368; bh=/N5LA3VZRheX/0Vim93hGoS5MshyffKsHn+ugEInpsU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=d/MLPwEBBiqRT+DvBnqFclfRSiEfy5PaUKHX9mJZE1KDQLd/7ydZMsIPHhZBOqcHF yE8iMG9AWvOPwgo7ID04znjQZpj4K+DsLal1e2Q51GzwEPkpKVQYYKXtRomLqvdP2P aN8bEOZI8Ga8VUPhDEN8kpSP+Zr8rPaU1USvRTKQ= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 80DB561197; Thu, 19 Sep 2019 23:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1568936367; bh=/N5LA3VZRheX/0Vim93hGoS5MshyffKsHn+ugEInpsU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=fcaT3HBOanXCmHj2+Xb2t7at/xuhDH6/FyHlyTAReApGsnPC8QmNm9Xb+PXi8QCkT 8gu/S7l1I/tM8CwrGm2PBCrjGqaXZbzu8uUbVv2tr8QGGRKJAsdn+WvUgvSfidFl4Y 4ImccfN01246ZwoVDIeWwlG0zmrvA/xO6msMyu7g= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 19 Sep 2019 16:39:27 -0700 From: mnalajal@codeaurora.org To: Greg KH Cc: Bjorn Andersson , rafael@kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Walleij Subject: Re: [PATCH] base: soc: Export soc_device_to_device API In-Reply-To: <20190919224514.GA447028@kroah.com> References: <1568927624-13682-1-git-send-email-mnalajal@codeaurora.org> <20190919213203.GA395325@kroah.com> <20190919215300.GC1418@minitux> <20190919215836.GA426988@kroah.com> <20190919221456.GA63675@minitux> <20190919222525.GA445429@kroah.com> <20190919224017.GB63675@minitux> <20190919224514.GA447028@kroah.com> Message-ID: X-Sender: mnalajal@codeaurora.org User-Agent: Roundcube Webmail/1.2.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-09-19 15:45, Greg KH wrote: > On Thu, Sep 19, 2019 at 03:40:17PM -0700, Bjorn Andersson wrote: >> On Thu 19 Sep 15:25 PDT 2019, Greg KH wrote: >> >> > On Thu, Sep 19, 2019 at 03:14:56PM -0700, Bjorn Andersson wrote: >> > > On Thu 19 Sep 14:58 PDT 2019, Greg KH wrote: >> > > >> > > > On Thu, Sep 19, 2019 at 02:53:00PM -0700, Bjorn Andersson wrote: >> > > > > On Thu 19 Sep 14:32 PDT 2019, Greg KH wrote: >> > > > > >> > > > > > On Thu, Sep 19, 2019 at 02:13:44PM -0700, Murali Nalajala wrote: >> > > > > > > If the soc drivers want to add custom sysfs entries it needs to >> > > > > > > access "dev" field in "struct soc_device". This can be achieved >> > > > > > > by "soc_device_to_device" API. Soc drivers which are built as a >> > > > > > > module they need above API to be exported. Otherwise one can >> > > > > > > observe compilation issues. >> > > > > > > >> > > > > > > Signed-off-by: Murali Nalajala >> > > > > > > --- >> > > > > > > drivers/base/soc.c | 1 + >> > > > > > > 1 file changed, 1 insertion(+) >> > > > > > > >> > > > > > > diff --git a/drivers/base/soc.c b/drivers/base/soc.c >> > > > > > > index 7c0c5ca..4ad52f6 100644 >> > > > > > > --- a/drivers/base/soc.c >> > > > > > > +++ b/drivers/base/soc.c >> > > > > > > @@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev) >> > > > > > > { >> > > > > > > return &soc_dev->dev; >> > > > > > > } >> > > > > > > +EXPORT_SYMBOL_GPL(soc_device_to_device); >> > > > > > > >> > > > > > > static umode_t soc_attribute_mode(struct kobject *kobj, >> > > > > > > struct attribute *attr, >> > > > > > >> > > > > > What in-kernel driver needs this? >> > > > > > >> > > > > >> > > > > Half of the drivers interacting with the soc driver calls this API, >> > > > > several of these I see no reason for being builtin (e.g. >> > > > > ux500 andversatile). So I think this patch makes sense to allow us to >> > > > > build these as modules. >> > > > > >> > > > > > Is linux-next breaking without this? >> > > > > > >> > > > > >> > > > > No, we postponed the addition of any sysfs attributes in the Qualcomm >> > > > > socinfo driver. >> > > > > >> > > > > > We don't export things unless we have a user of the export. >> > > > > > >> > > > > > Also, adding "custom" sysfs attributes is almost always not the correct >> > > > > > thing to do at all. The driver should be doing it, by setting up the >> > > > > > attribute group properly so that the driver core can do it automatically >> > > > > > for it. >> > > > > > >> > > > > > No driver should be doing individual add/remove of sysfs files. If it >> > > > > > does so, it is almost guaranteed to be doing it incorrectly and racing >> > > > > > userspace. >> > > > > > >> > > > > >> > > > > The problem here is that the attributes are expected to be attached to >> > > > > the soc driver, which is separate from the platform-specific drivers. So >> > > > > there's no way to do platform specific attributes the right way. >> > > > > >> > > > > > And yes, there's loads of in-kernel examples of doing this wrong, I've >> > > > > > been working on fixing that up, look at the patches now in Linus's tree >> > > > > > for platform and USB drivers that do this as examples of how to do it >> > > > > > right. >> > > > > > >> > > > > >> > > > > Agreed, this patch should not be used as an approval for any crazy >> > > > > attributes; but it's necessary in order to extend the soc device's >> > > > > attributes, per the current design. >> > > > >> > > > Wait, no, let's not let the "current design" remain if it is broken! >> > > > >> > > > Why can't the soc driver handle the attributes properly so that the >> > > > individual driver doesn't have to do the create/remove? >> > > > >> > > >> > > The custom attributes that these drivers want to add to the common ones >> > > are known in advance, so I presume we could have them passed into >> > > soc_device_register() and registered together with the common >> > > attributes... >> > > >> > > It sounds like it's worth a prototype. >> > >> > Do you have an in-kernel example I can look at to get an idea of what is >> > needed here? >> > >> >> realview_soc_probe(), in drivers/soc/versatile/soc-realview.c, >> implements the current mechanism of acquiring the soc's struct device >> and then issuing a few device_create_file calls on that. > > That looks to be a trivial driver to fix up. Look at 6d03c140db2e > ("USB: phy: fsl-usb: convert platform driver to use dev_groups") as an > example of how to do this. > > Also gotta love the total lack of error checking when calling > device_create_file() in that driver :( > > thanks, > > greg k-h You can see example here https://android.googlesource.com/kernel/msm/+/android-7.1.0_r0.2/drivers/soc/qcom/socinfo.c#1356 I want to add the custom entries to "soc" device path. This can be achieved if i go with "dev_groups"? sys/devices/soc0 # ls -l total 0 -r--r--r-- 1 root 0 4096 Jan 1 00:01 family -r--r--r-- 1 root 0 4096 Jan 1 00:01 machine drwxr-xr-x 2 root 0 0 Jan 1 00:01 power -r--r--r-- 1 root 0 4096 Jan 1 00:01 revision -r--r--r-- 1 root 0 4096 Jan 1 00:01 serial_number lrwxrwxrwx 1 root 0 0 Jan 1 00:01 subsystem -> ../../bus/soc -rw-r--r-- 1 root 0 4096 Jan 1 00:01 uevent