Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp624200imm; Fri, 21 Sep 2018 05:48:33 -0700 (PDT) X-Google-Smtp-Source: ANB0VdahjdPCAsvUDLz0iGOq6CPtTky0vluzT+NWSLnvcbU3gKOea9qZbZa9q37oY4KaQO5DCkQv X-Received: by 2002:a17:902:8bc8:: with SMTP id r8-v6mr45079375plo.100.1537534113693; Fri, 21 Sep 2018 05:48:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537534113; cv=none; d=google.com; s=arc-20160816; b=mia79jdi83WurW+IFYBnTrAxMilyXHMnW/ItnNDYJE1PLuNbx/d/z4wKt+tqz/YGkj Z9J3vVAFxAcryNapvJHsFz6b79Dd8Z7rUz69+SQ7nmMETE64/omyKrs/o2Hs8RXi6oZj txUvlhUb5f41VKiIRI2HNPgGK9bNZd8laZbfpMIck7PxNq2qpJ6Uw6EAWENUGQLUHIDN Wag2Yia5j3XT5RUxJw3e8f+D/cMhIwiy7giPjl1ME7j2IUgBYmc5byplpiBAE+DOR6x9 hB+RgmMSPsxJyvGPeAFB3LTi2XTLHfMcVFGkFRIMVx055ygTyNJAD5MIw1QYi+fUQLsB 54og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=0xhR8c49X1oItXOMFB/yvowhp2isimQUTwFmgWM51eQ=; b=c7/x/1AZU/PobFePY+oIypHpO+c9/7I7bBeEdTt0s7Iw24DBWoOdAnw4FBSFTPxV09 Hb6+CKz3DJlXCKvByQX2pev7fZHfwrwjNGmVbuew/ix8W/ZpYuN+riu1+Sk5WCXU4v38 Haf7XLzlNNOpjhi8h7dvcKqOHNexU/CtuioOXnmHN9FAEawXRxj05rTyiGlYYNmdbmg1 fn7Nzz73yuwTgcSmEc0/r12pwHSYxkQ9+gEbTIThp4ekFd/FTgc3euHlldHOsRNRNtTn xQbZ23QFDVAa8jib66Itk6l1PSVeLCQGgSjQYHgVlMV7HaIx6TrW/oPt9qqpM8Gz1ybZ pC9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="mD/2lxL8"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r7-v6si3594968pgf.620.2018.09.21.05.48.17; Fri, 21 Sep 2018 05:48: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=@gmail.com header.s=20161025 header.b="mD/2lxL8"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389928AbeIUSgu (ORCPT + 99 others); Fri, 21 Sep 2018 14:36:50 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:42529 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728098AbeIUSgu (ORCPT ); Fri, 21 Sep 2018 14:36:50 -0400 Received: by mail-qk1-f196.google.com with SMTP id w73-v6so2318360qkb.9; Fri, 21 Sep 2018 05:48:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0xhR8c49X1oItXOMFB/yvowhp2isimQUTwFmgWM51eQ=; b=mD/2lxL84SwBiySzcuyc8MpwT4Fa2Ke09PsLN5efOw9gHDHYzKOL2RmgdS1oGCgXhF Sy7Wp99NDAmm+4FeqyYJv+8MvC6h9RPPp961zFG80+xawjN3mxNK31zpZ/zUyBs4WIi2 PwFCV8v0wzMXmgUxYz/+mEUSrHRHH68OeaOTazi1LilvZ4SphBs3hd2Oii7DfLMS/gGA OZRiFzLof1/VuGzy93s/J7cb5mdxGEAPaaE6qV2N9roAVVT2T3oLMnwJqqtCXeezhm2B O3p1SlovflLdf8UWQfFsJYOwdxheoZqMWdPdDtU6H1XNZa5Xnmyopbtgr+46I7Wrm0eY zLgQ== 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=0xhR8c49X1oItXOMFB/yvowhp2isimQUTwFmgWM51eQ=; b=oxVF7OcDtl87YOPAu2JWTxH0gVBjFv4JZvrsSqqKj+FMjm6fZlwlPC5sX6rxTqy3Rj Fe2X4A/LeYOdeGq9pbfML4BhaeBHWyGRIrB/Lsvcha3It7zxn+RIwCWoa4EgUBX28W4n r9TD8zZBvgwzKacsW9YaSI2ecH2uCLEZ8DmQLCjrLBNoYF+4qUdtvp6Y/97Ay2pqVnt+ 3bqlb+lyFAfLJj/rmlgt/eRpLYigDvkhhnExjhejHuPpZ6a1TBe7HqDCt+8szrtWlt6X 9+9YMg2uIxMudsiCZ0eVxUtHhDr7L6fB5pCQ7bJt4fhpg3bgtcHB6sT2uipV4EhwrEDY XXdg== X-Gm-Message-State: APzg51CGyTXYyWyqPbE4XqMDqUqUJz6ISrG/bHPxDQuwfMFkHcCFCCu2 9U4I95KZqGG2Dc63SWw7+AY4wKaQ2KkLrinq5Q8= X-Received: by 2002:a37:270f:: with SMTP id n15-v6mr10995967qkn.33.1537534085159; Fri, 21 Sep 2018 05:48:05 -0700 (PDT) MIME-Version: 1.0 References: <20180920223436.202454-1-mka@chromium.org> <20180920223436.202454-2-mka@chromium.org> <20180921071312.gg7xshwa2ro3hiix@kekkonen.localdomain> In-Reply-To: <20180921071312.gg7xshwa2ro3hiix@kekkonen.localdomain> From: Andy Shevchenko Date: Fri, 21 Sep 2018 15:47:54 +0300 Message-ID: Subject: Re: [PATCH 1/2] device property: Add device_get_bd_address() and fwnode_get_bd_address() To: Sakari Ailus Cc: Matthias Kaehlcke , Greg Kroah-Hartman , "Rafael J. Wysocki" , mw@semihalf.com, Andy Shevchenko , Sinan Kaya , Marcel Holtmann , Johan Hedberg , Linux Kernel Mailing List , linux-bluetooth@vger.kernel.org, bgodavar@codeaurora.org, Loic Poulain , Brian Norris Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 21, 2018 at 10:16 AM Sakari Ailus wrote: > > Hi Matthias, > > On Thu, Sep 20, 2018 at 03:34:35PM -0700, Matthias Kaehlcke wrote: > > Provide an API for Bluetooth drivers to retrieve the Bluetooth Device > > address (BD_ADDR) for a device. If the device node has a property > > 'local-bd-address' the BD address is read from this property. > > I have nothing to object for the idea and agree fully on Sakari's comments. After addressing them, fill free to add my Reviewed-by: Andy Shevchenko > > Signed-off-by: Matthias Kaehlcke > > --- > > drivers/base/property.c | 49 ++++++++++++++++++++++++++++++++++++++++ > > include/linux/property.h | 4 ++++ > > 2 files changed, 53 insertions(+) > > > > diff --git a/drivers/base/property.c b/drivers/base/property.c > > index 240ab5230ff6..8fe546b9805a 100644 > > --- a/drivers/base/property.c > > +++ b/drivers/base/property.c > > @@ -18,6 +18,8 @@ > > #include > > #include > > > > +#define BD_ADDR_LEN 6 > > + > > struct property_set { > > struct device *dev; > > struct fwnode_handle fwnode; > > @@ -1315,6 +1317,53 @@ void *device_get_mac_address(struct device *dev, char *addr, int alen) > > } > > EXPORT_SYMBOL(device_get_mac_address); > > > > +/** > > + * fwnode_get_bd_address - Get the Bluetooth Device Address (BD_ADDR) from the > > + * firmware node > > + * @fwnode: Pointer to the firmware node > > + * @addr: Address of buffer to store the BD address in > > + * @alen: Length of the buffer pointed to by addr, should be BD_ADDR_LEN > > + * > > + * Search the firmware node for 'local-bd-address'. > > + * > > + * All-zero BD addresses are rejected, because those could be properties > > + * that exist in the firmware tables, but were not updated by the firmware. For > > + * example, the DTS could define 'local-bd-address', with zero BD addresses. > > + */ > > +int fwnode_get_bd_address(struct fwnode_handle *fwnode, u8 *addr, int alen) > > How about using bdaddr_t instead? The original caller was casting it to u8 > probably just because there was no function specifically for this purpose. > > I wonder if this also should be made depend on CONFIG_BT. The fwnode > framework is unconditionally a part of the kernel and it's not very big at > the moment but adding stuff little by little will add up eventually. > > > +{ > > + u8 buf[BD_ADDR_LEN]; > > + int ret; > > + > > + if (alen != BD_ADDR_LEN) > > + return -EINVAL; > > + > > + ret = fwnode_property_read_u8_array(fwnode, "local-bd-address", > > + buf, alen); > > + if (ret < 0) > > + return ret; > > + if (is_zero_ether_addr(buf)) > > + return -ENODATA; > > + > > + memcpy(addr, buf, BD_ADDR_LEN); > > + > > + return 0; > > +} > > +EXPORT_SYMBOL(fwnode_get_bd_address); > > + > > +/** > > + * device_get_bd_address - Get the Bluetooth Device Address (BD_ADDR) for a > > + * given device > > + * @dev: Pointer to the device > > + * @addr: Address of buffer to store the BD address in > > + * @alen: Length of the buffer pointed to by addr, should be BD_ADDR_LEN > > + */ > > +int device_get_bd_address(struct device *dev, u8 *addr, int alen) > > +{ > > + return fwnode_get_bd_address(dev_fwnode(dev), addr, alen); > > +} > > +EXPORT_SYMBOL(device_get_bd_address); > > + > > /** > > * fwnode_irq_get - Get IRQ directly from a fwnode > > * @fwnode: Pointer to the firmware node > > diff --git a/include/linux/property.h b/include/linux/property.h > > index ac8a1ebc4c1b..4e2f1b276f4f 100644 > > --- a/include/linux/property.h > > +++ b/include/linux/property.h > > @@ -287,9 +287,13 @@ int device_get_phy_mode(struct device *dev); > > > > void *device_get_mac_address(struct device *dev, char *addr, int alen); > > > > +int device_get_bd_address(struct device *dev, u8 *addr, int alen); > > + > > int fwnode_get_phy_mode(struct fwnode_handle *fwnode); > > void *fwnode_get_mac_address(struct fwnode_handle *fwnode, > > char *addr, int alen); > > +int fwnode_get_bd_address(struct fwnode_handle *fwnode, > > + u8 *addr, int alen); > > This would be a good opportunity to add a newline here, and avoid adding > one after device_get_mac_address(). > > > struct fwnode_handle *fwnode_graph_get_next_endpoint( > > const struct fwnode_handle *fwnode, struct fwnode_handle *prev); > > struct fwnode_handle * > > -- > Regards, > > Sakari Ailus > sakari.ailus@linux.intel.com -- With Best Regards, Andy Shevchenko