Return-Path: From: "Zhang, Ming" To: Yunhan Wang , ERAMOTO Masaya CC: "linux-bluetooth@vger.kernel.org" Subject: RE: [PATCH BlueZ] client: Fix default_ctrl change when new adapter is found Date: Fri, 1 Sep 2017 21:06:17 +0000 Message-ID: References: <20170901035615.95402-1-yunhanw@google.com> In-Reply-To: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org List-ID: SGVsbG8sIA0KDQpDYW4gYW55Ym9keSBnaXZlIGEgaGVscCB3aXRoIEJsdWVaIHV0aWxpdHkgYmx1 ZXRvb3RoY3RsPyANCi0gInJlYWQiIGFuZCAid3JpdGUiIGNvbW1hbmRzIHNlZW0gbm90IHdvcmtp bmc/IGFsd2F5cyByZXBvcnQgIm5vIGF0dHJpYnV0ZSBzZWxlY3RlZCIsIHVzaW5nICJzZWxlY3Qt YXR0cmlidXRlIiBmaXJzdCBkb2Vzbid0IGhlbHAuIA0KDQpUaGFua3MsIA0KTWluZw0KDQotLS0t LU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KRnJvbTogbGludXgtYmx1ZXRvb3RoLW93bmVyQHZnZXIu a2VybmVsLm9yZyBbbWFpbHRvOmxpbnV4LWJsdWV0b290aC1vd25lckB2Z2VyLmtlcm5lbC5vcmdd IE9uIEJlaGFsZiBPZiBZdW5oYW4gV2FuZw0KU2VudDogRnJpZGF5LCBTZXB0ZW1iZXIgMDEsIDIw MTcgMTI6NDMgQU0NClRvOiBFUkFNT1RPIE1hc2F5YSA8ZXJhbW90by5tYXNheWFAanAuZnVqaXRz dS5jb20+DQpDYzogbGludXgtYmx1ZXRvb3RoQHZnZXIua2VybmVsLm9yZw0KU3ViamVjdDogUmU6 IFtQQVRDSCBCbHVlWl0gY2xpZW50OiBGaXggZGVmYXVsdF9jdHJsIGNoYW5nZSB3aGVuIG5ldyBh ZGFwdGVyIGlzIGZvdW5kDQoNCkhpLCBFUkFNT1RPDQoNCmNhY2hlX2N0cmwgaXMgb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