Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp6870345imm; Tue, 24 Jul 2018 04:42:49 -0700 (PDT) X-Google-Smtp-Source: AAOMgpejGFA4+CgcUlhjLDBFLLihb7d+heL0Z30kGbMOeiXAz85dVHUtMNTgFKfqzjKBZsrx5W9S X-Received: by 2002:a17:902:8486:: with SMTP id c6-v6mr16525142plo.283.1532432569170; Tue, 24 Jul 2018 04:42:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532432569; cv=none; d=google.com; s=arc-20160816; b=WOcC/vrcwGX31bZCggieZoVzWdotUP5KhZxBY/yy+o5Q3s1sUKBuTmCU8kZ4/rLFbt t/jd7mKtUi/7Xuh6zrB4iBQb+tOPY/x9H7tziNlzkHFAIhyMjGZTW2KjVqVg8k2Ja+je MR0sdVL1k+eh2ePwRqLNMdtoc1fk/rSAKuqKc9G1rTCmrCTTzIPvDzYVG71EPoHN806h EavnGNyKZWXnNmf5WMHRDmxcyIZIHhMDcwsNPDgmWguOief6Mr2ycEXO+s2rOZYDsNOf S0L77X4bREIR/FtVpKVGxYw3B1kxEZPRlwx2fZp0L5b3iy4FG39oUDBevPAlzTgoh7x5 hNtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:mime-version:accept-language:in-reply-to :references:message-id:date:thread-index:thread-topic:subject:cc:to :from:arc-authentication-results; bh=g566xaNS1Z8soefEm+nB/XWmotpg7mImXkJ7sCKPTaA=; b=w/LnBXC2m8lhz3k/f3A4E7B4iRUm8qjzHyKB1+i6XJapDolsERUJPRgyMOL/dsHtrO OaypkfPie6BgSTBzmDX84Y1NineKky/bIUQTUf96IWwhDBDhC4UdktnL+NKfXHTeBoal a+V+C2i0ct2czSxN4/w+s7LeRLc0qsZ87ERMffRGMmhGenjRF8kVI7r+1QG3iL2jPVkN +UTf+ktpLQGObOFnm3SQnb4VQw8naD+yXQ/c4+QF4dZvjtnHd0cyKUXjXNTeQ17x96R/ qlYxloZ9zTWWpTUiRfqa9stpZZZG2AVn+YoLLid2mirBsri6bhGsZxhAOZxixb4AM5K7 0KJw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t67-v6si10083209pfd.364.2018.07.24.04.42.34; Tue, 24 Jul 2018 04:42:49 -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; 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 S2388435AbeGXMrZ convert rfc822-to-8bit (ORCPT + 99 others); Tue, 24 Jul 2018 08:47:25 -0400 Received: from enterprise02.smtp.diehl.com ([193.201.238.220]:61312 "EHLO enterprise02.smtp.diehl.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388256AbeGXMrY (ORCPT ); Tue, 24 Jul 2018 08:47:24 -0400 X-$ESA-Groupmapping: true X-IronPort-AV: E=Sophos;i="5.51,397,1526335200"; d="scan'208";a="34467533" From: Denis OSTERLAND To: "a.zummo@towertech.it" , "alexandre.belloni@bootlin.com" CC: "linux-kernel@vger.kernel.org" , "robh+dt@kernel.org" , "m.grzeschik@pengutronix.de" , "devicetree@vger.kernel.org" , "mark.rutland@arm.com" , "linux-rtc@vger.kernel.org" , "kernel@pengutronix.de" , Denis OSTERLAND Subject: [PATCH v5 1/5] rtc: sysfs: facilitate attribute add to rtc device Thread-Topic: [PATCH v5 1/5] rtc: sysfs: facilitate attribute add to rtc device Thread-Index: AQHUI0HYwv+nEZqvMUK9Qne5+qXuFA== Date: Tue, 24 Jul 2018 11:31:22 +0000 Message-ID: <20180724095437.6016-2-Denis.Osterland@diehl.com> References: <20180724095437.6016-1-Denis.Osterland@diehl.com> In-Reply-To: <20180724095437.6016-1-Denis.Osterland@diehl.com> Accept-Language: de-DE, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Evolution 3.18.5.2-0ubuntu3.2 MIME-Version: 1.0 X-TrailerSkip: 1 X-GBS-PROC: byQFdw3ukCM+zy1/poiPc3S+cPOwesVRp3YOtqJ1nLGzDTCHgOUEK+Oxjt5YvNJU X-TNEFEvaluated: 1 Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset="iso-8859-1" Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Denis Osterland This patches addresses following problem: rtc_allocate_device devm_device_add_group <-- kernel oops / null pointer, because sysfs entry does not yet exist rtc_register_device rc = devm_device_add_group if (rc) return rc; <-- forbidden to return error code after device register This patch adds rtc_add_group(s) functions. The functions store the sum of attribute groups as device resource. Signed-off-by: Denis Osterland --- drivers/rtc/rtc-core.h | 13 +++++++++++++ drivers/rtc/rtc-sysfs.c | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/drivers/rtc/rtc-core.h b/drivers/rtc/rtc-core.h index 0abf98983e13..c74537d03644 100644 --- a/drivers/rtc/rtc-core.h +++ b/drivers/rtc/rtc-core.h @@ -40,9 +40,22 @@ static inline void rtc_proc_del_device(struct rtc_device *rtc) #ifdef CONFIG_RTC_INTF_SYSFS const struct attribute_group **rtc_get_dev_attribute_groups(void); +int rtc_add_group(struct rtc_device *rtc, const struct attribute_group *grp); +int rtc_add_groups(struct rtc_device *rtc, + const struct attribute_group **grps); #else static inline const struct attribute_group **rtc_get_dev_attribute_groups(void) { return NULL; } +static inline +int rtc_add_group(struct rtc_device *rtc, const struct attribute_group *grp) +{ + return 0; +} +static inline +int rtc_add_groups(struct rtc_device *rtc, const struct attribute_group **grps) +{ + return 0; +} #endif diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c index 454da38c6012..498e65f13686 100644 --- a/drivers/rtc/rtc-sysfs.c +++ b/drivers/rtc/rtc-sysfs.c @@ -317,3 +317,46 @@ const struct attribute_group **rtc_get_dev_attribute_groups(void) { return rtc_attr_groups; } + +int rtc_add_groups(struct rtc_device *rtc, const struct attribute_group **grps) +{ + size_t old_cnt = 0, add_cnt = 0, new_cnt; + const struct attribute_group **groups, **old; + + if (rtc->registered) + return -EINVAL; + if (!grps) + return -EINVAL; + + groups = rtc->dev.groups; + if (groups) + for (; *groups; groups++) + old_cnt++; + + for (groups = grps; *groups; groups++) + add_cnt++; + + new_cnt = old_cnt + add_cnt + 1; + groups = devm_kcalloc(&rtc->dev, new_cnt, sizeof(*groups), GFP_KERNEL); + if (IS_ERR_OR_NULL(groups)) + return PTR_ERR(groups); + memcpy(groups, rtc->dev.groups, old_cnt*sizeof(*groups)); + memcpy(groups+old_cnt, grps, add_cnt*sizeof(*groups)); + groups[old_cnt+add_cnt] = NULL; + + old = rtc->dev.groups; + rtc->dev.groups = groups; + if (old && old != rtc_attr_groups) + devm_kfree(&rtc->dev, old); + + return 0; +} +EXPORT_SYMBOL(rtc_add_groups); + +int rtc_add_group(struct rtc_device *rtc, const struct attribute_group *grp) +{ + const struct attribute_group *groups[] = { grp, NULL }; + + return rtc_add_groups(rtc, groups); +} +EXPORT_SYMBOL(rtc_add_group); -- 2.18.0 Diehl Connectivity Solutions GmbH Gesch?ftsf?hrung: Horst Leonberger Sitz der Gesellschaft: N?rnberg - Registergericht: Amtsgericht N?rnberg: HRB 32315 ___________________________________________________________________________________________________ Der Inhalt der vorstehenden E-Mail ist nicht rechtlich bindend. Diese E-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte Informationen. Informieren Sie uns bitte, wenn Sie diese E-Mail faelschlicherweise erhalten haben. Bitte loeschen Sie in diesem Fall die Nachricht. Jede unerlaubte Form der Reproduktion, Bekanntgabe, Aenderung, Verteilung und/oder Publikation dieser E-Mail ist strengstens untersagt. The contents of the above mentioned e-mail is not legally binding. This e-mail contains confidential and/or legally protected information. Please inform us if you have received this e-mail by mistake and delete it in such a case. Each unauthorized reproduction, disclosure, alteration, distribution and/or publication of this e-mail is strictly prohibited.