Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp312563imm; Fri, 21 Sep 2018 00:13:50 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY4kr8hGYkItZfKi7Inu/bwl/Y3nzdTu8jL6kYZL9msEL2e0TUfTebda/WbkXEXjLhw7FfN X-Received: by 2002:a17:902:968d:: with SMTP id n13-v6mr10536612plp.33.1537514030780; Fri, 21 Sep 2018 00:13:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537514030; cv=none; d=google.com; s=arc-20160816; b=i7SyjzB1nV10C+7kOHiKyL4ebVhVSx58Jqf6D4LrAhaVKDTS+iDl8z6R/CR4qTdB+K 63ISlfZf0OI3SfDg48EanJ3tgfDsqB9EYr/stZg7sfNEvp2Xd35QDLSWXTzAeiafJe4m lQFrgvFS2RJSJO8JAzC3Ea2AJ0TZiUjNsBj9hKNQKT5+9Vl6vPynr4yjRGCsPe3MHN78 g+itp49NvWpOV5vgGD+ZMJMKC2L7EgdFeI/yGzBbOZOw9xzLgJFav8cVLqjYT2b6i9zB dUBsKQiFw9WsMveWvppj9BxTt3ngostiAKz7qkebFBCVdEifdZq+IZrDy5oed6JeCJnB x0Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=nwCWGxIvmI5JmL6foCXtk2mri5HATbQEG9ji+JhdKck=; b=EnKCKHBE/xXqpHIAqgH9123fXUwin+1bo1PG7i57Or5R7NzVZJbaNR3S3FsWJRJd2H CoGmewu9hQrybmrg92o28e5VC2Wp38xA7DGvd/EFgfIRaWQYp16D8QPCie+ExcQs9gsy pg/0pvYK1A7EmitehgH5H7U/v21zkfqZBJEszeNIeH3yeijsTCYCZqkW7ChQkfynLUNY cMIS3Mj2ReZ1CVmGdi4fWG3gydCDwJr/HjaxIKWPdKPCJ0hQYPcr1MH5iUbvlr73lpjF OH0D1Xutli5cVSg/DY0wl8tIOBRvDpN9rlOoCJaglh5t8U0NL0fAinF+rExLguBK5iNM yQJw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d70-v6si28727102pfd.114.2018.09.21.00.13.34; Fri, 21 Sep 2018 00:13:50 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389225AbeIUNBB (ORCPT + 99 others); Fri, 21 Sep 2018 09:01:01 -0400 Received: from mga07.intel.com ([134.134.136.100]:58062 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727795AbeIUNBB (ORCPT ); Fri, 21 Sep 2018 09:01:01 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Sep 2018 00:13:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,284,1534834800"; d="scan'208";a="85392786" Received: from lwallet-mobl2.ger.corp.intel.com (HELO kekkonen.fi.intel.com) ([10.249.254.69]) by orsmga003.jf.intel.com with SMTP; 21 Sep 2018 00:13:13 -0700 Received: by kekkonen.fi.intel.com (Postfix, from userid 1000) id BCA9621F17; Fri, 21 Sep 2018 10:13:12 +0300 (EEST) Date: Fri, 21 Sep 2018 10:13:12 +0300 From: Sakari Ailus To: Matthias Kaehlcke Cc: Greg Kroah-Hartman , "Rafael J . Wysocki" , Marcin Wojtas , Andy Shevchenko , Sinan Kaya , Marcel Holtmann , Johan Hedberg , linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, Balakrishna Godavarthi , Loic Poulain , Brian Norris Subject: Re: [PATCH 1/2] device property: Add device_get_bd_address() and fwnode_get_bd_address() Message-ID: <20180921071312.gg7xshwa2ro3hiix@kekkonen.localdomain> References: <20180920223436.202454-1-mka@chromium.org> <20180920223436.202454-2-mka@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180920223436.202454-2-mka@chromium.org> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > 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