Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp24128ybp; Thu, 3 Oct 2019 14:12:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5sdWV68wAMsqdGi6xsB82o1tcs2XgZN+J6YIWZ3zjLdFj8jbiWANAnC69hpMG1rCqGT/k X-Received: by 2002:a17:906:32c2:: with SMTP id k2mr9558280ejk.140.1570137153434; Thu, 03 Oct 2019 14:12:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570137153; cv=none; d=google.com; s=arc-20160816; b=B1tKyjFu5AP7up9GuRnKj6Zjkama8qcqCA9/LV99JpG+gMBq/g4Oerew97qCdd5cH7 B2rRKJ59vwGmrjbRf/bJaB5sWU1LEYzEyb4EQ3TOSq8w89dvAJQ5j0IbZDXaX/nTVVn1 HrE3s9gg24KkUkYrJkPZ/P3knraaWQH/8JIAk1XwNvIuiTmkNcduLYzHLyEyQAWeOZ+C s04qnC2Fm5C7IkgVEWBbaDsZx1pUR0dECFRhHKdjyYO6d5EKpmiBMvvsM6GYVqjwj78K P0ZT32MKxp4VzmWeEJyXouz15mua9wNU/dyilUxoHXYQTsVmpLh8zfm70L84GstFbmZJ 77wQ== 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=oxAJ9TmZ0CP0qq07PayV5/75jPOk8vi46IigBA5O7Qk=; b=KXk6+Lazqde+cbrDtZfsNhD5nG9q/YIBGp8qDCJQyN/H01pojXJafrwOCoIaooyVh7 4slRqS7Z4ktyoe4Nr8A/noS45UiNNsVASGqbLwW0qaMoegYwouM3OtTyRENob0VeZEJB YiXPouSS7zPIXmajuvKuhgtcHev3P5Q2Z70LVMdlfhFgEO/Udf6HMvUpnzy961FZcrJ4 lZqYfl7YH57yPbJjm6K7Fi9/vlNAzzqlp9zIx+dgYMPmDQmeiER3S6HtLSAKPT2tcvxj 8EGr6Jm9kINbYGpG8n4cQMV+sd6fHNYj1aYVdETDxdeagBYTAQ0m/HVcfTCw1Km6wgNh mnNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=dFQI5g+s; dkim=pass header.i=@codeaurora.org header.s=default header.b=WyhoZ2nq; 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 c26si2281320edx.353.2019.10.03.14.12.08; Thu, 03 Oct 2019 14:12:33 -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=dFQI5g+s; dkim=pass header.i=@codeaurora.org header.s=default header.b=WyhoZ2nq; 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 S1731639AbfJCVLF (ORCPT + 99 others); Thu, 3 Oct 2019 17:11:05 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:56462 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727789AbfJCVLE (ORCPT ); Thu, 3 Oct 2019 17:11:04 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 64B306155E; Thu, 3 Oct 2019 21:11:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1570137063; bh=6Y7obBeUmhg7/SW9V/ajjOEqPTX+NgguganrNVb4VwI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=dFQI5g+svq2BS+x87vr+N0qhKq7jPQfnR0UVViT3hxAmI8cX7AMgpDdWo4rMkUpjv ooCP6mBjOHVuWAmUjz4xpx/Bqu6yZ1mf/d3VsLb8WIbTR8mJDbpvTYQQsGDcfsx7fX nJqAVdhjpCQgkl6+Pg7C22rJ5L02hxp15glCLyL4= 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 71EE26034E; Thu, 3 Oct 2019 21:11:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1570137062; bh=6Y7obBeUmhg7/SW9V/ajjOEqPTX+NgguganrNVb4VwI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=WyhoZ2nqBpVdaN1DlEfAP3JK+Jb6VszufCRKdeQt+e2H24sqAdihEW4iWu/me4lCk tlm6mvOhhzkE5nnNaL9IrgI6RdzrZoc7VXBSCOFZf+oGWEu6rpWWGJdAdaDGC3XuDZ 2vn3qDxmtQrvhUl1nnLusFJ0JEEnUX4evB52kKuE= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 03 Oct 2019 14:11:02 -0700 From: mnalajal@codeaurora.org To: Greg KH Cc: rafael@kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, bjorn.andersson@linaro.org Subject: Re: [PATCH] base: soc: Handle custom soc information sysfs entries In-Reply-To: <20191003183357.GA3580296@kroah.com> References: <1570061174-4918-1-git-send-email-mnalajal@codeaurora.org> <20191003070610.GC1814133@kroah.com> <0d219d344cea82b5f6c1ab23341de25b@codeaurora.org> <20191003183357.GA3580296@kroah.com> Message-ID: <6e7d5e14c231d2fe51c7ae78d5d0dee8@codeaurora.org> 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-10-03 11:33, Greg KH wrote: > On Thu, Oct 03, 2019 at 11:23:45AM -0700, mnalajal@codeaurora.org > wrote: >> On 2019-10-03 00:06, Greg KH wrote: >> > On Wed, Oct 02, 2019 at 05:06:14PM -0700, Murali Nalajala wrote: >> > > Soc framework exposed sysfs entries are not sufficient for some >> > > of the h/w platforms. Currently there is no interface where soc >> > > drivers can expose further information about their SoCs via soc >> > > framework. This change address this limitation where clients can >> > > pass their custom entries as attribute group and soc framework >> > > would expose them as sysfs properties. >> > > >> > > Signed-off-by: Murali Nalajala >> > > --- >> > > drivers/base/soc.c | 26 ++++++++++++++++++-------- >> > > include/linux/sys_soc.h | 1 + >> > > 2 files changed, 19 insertions(+), 8 deletions(-) >> > > >> > > diff --git a/drivers/base/soc.c b/drivers/base/soc.c >> > > index 7c0c5ca..ec70a58 100644 >> > > --- a/drivers/base/soc.c >> > > +++ b/drivers/base/soc.c >> > > @@ -15,6 +15,8 @@ >> > > #include >> > > #include >> > > >> > > +#define NUM_ATTR_GROUPS 3 >> > > + >> > > static DEFINE_IDA(soc_ida); >> > > >> > > static ssize_t soc_info_get(struct device *dev, >> > > @@ -104,11 +106,6 @@ static ssize_t soc_info_get(struct device *dev, >> > > .is_visible = soc_attribute_mode, >> > > }; >> > > >> > > -static const struct attribute_group *soc_attr_groups[] = { >> > > - &soc_attr_group, >> > > - NULL, >> > > -}; >> > > - >> > > static void soc_release(struct device *dev) >> > > { >> > > struct soc_device *soc_dev = container_of(dev, struct soc_device, >> > > dev); >> > > @@ -121,6 +118,7 @@ static void soc_release(struct device *dev) >> > > struct soc_device *soc_device_register(struct soc_device_attribute >> > > *soc_dev_attr) >> > > { >> > > struct soc_device *soc_dev; >> > > + const struct attribute_group **soc_attr_groups = NULL; >> > > int ret; >> > > >> > > if (!soc_bus_type.p) { >> > > @@ -136,10 +134,20 @@ struct soc_device *soc_device_register(struct >> > > soc_device_attribute *soc_dev_attr >> > > goto out1; >> > > } >> > > >> > > + soc_attr_groups = kzalloc(sizeof(*soc_attr_groups) * >> > > + NUM_ATTR_GROUPS, GFP_KERNEL); >> > > + if (!soc_attr_groups) { >> > > + ret = -ENOMEM; >> > > + goto out2; >> > > + } >> > > + soc_attr_groups[0] = &soc_attr_group; >> > > + soc_attr_groups[1] = soc_dev_attr->custom_attr_group; >> > > + soc_attr_groups[2] = NULL; >> > > + >> > > /* Fetch a unique (reclaimable) SOC ID. */ >> > > ret = ida_simple_get(&soc_ida, 0, 0, GFP_KERNEL); >> > > if (ret < 0) >> > > - goto out2; >> > > + goto out3; >> > > soc_dev->soc_dev_num = ret; >> > > >> > > soc_dev->attr = soc_dev_attr; >> > > @@ -151,14 +159,16 @@ struct soc_device *soc_device_register(struct >> > > soc_device_attribute *soc_dev_attr >> > > >> > > ret = device_register(&soc_dev->dev); >> > > if (ret) >> > > - goto out3; >> > > + goto out4; >> > > >> > > return soc_dev; >> > > >> > > -out3: >> > > +out4: >> > > ida_simple_remove(&soc_ida, soc_dev->soc_dev_num); >> > > put_device(&soc_dev->dev); >> > > soc_dev = NULL; >> > > +out3: >> > > + kfree(soc_attr_groups); >> > > out2: >> > > kfree(soc_dev); >> > > out1: >> > > diff --git a/include/linux/sys_soc.h b/include/linux/sys_soc.h >> > > index 48ceea8..d9b3cf0 100644 >> > > --- a/include/linux/sys_soc.h >> > > +++ b/include/linux/sys_soc.h >> > > @@ -15,6 +15,7 @@ struct soc_device_attribute { >> > > const char *serial_number; >> > > const char *soc_id; >> > > const void *data; >> > > + const struct attribute_group *custom_attr_group; >> > >> > Shouldn't you make this: >> > const struct attribute_group **soc_groups; >> > >> > to match up with the rest of the way the driver core works? >> Assumption is, soc drivers send their custom attribute group and soc >> framework has already soc_attr_group" (basic info exposed). >> With my changes i am combining these two groups and passing to >> "device_register()". >> I do not think soc drivers have a requirement where they can pass >> various >> groups rather one single group attribute. > > Ok, I guess this is "good enough" such that no individual SOC driver > will want to create subdirs and lots of fun like that. If they do, > then > we can change the api at that point in time :) > > thanks, > > greg k-h I trying to fix an issue in the existing "soc_device_register()" code. This looks to me a memory leak. ret = device_register(&soc_dev->dev); if (ret) goto out3; return soc_dev; out3: ida_simple_remove(&soc_ida, soc_dev->soc_dev_num); put_device(&soc_dev->dev); soc_dev = NULL; out2: kfree(soc_dev); Here we are assigning "soc_dev=NULL" before freeing. I see this assignment is unnecessary here.