Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp656721pxv; Thu, 15 Jul 2021 12:39:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiNd6vWJ4AdvkEx2ryNL9HX9Psh/GtD5fCpOLblpmyRoBgBKcOJqQEZ6vwB448SEPATUpR X-Received: by 2002:a17:906:32d8:: with SMTP id k24mr7207899ejk.422.1626377947283; Thu, 15 Jul 2021 12:39:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626377947; cv=none; d=google.com; s=arc-20160816; b=rgF/5tUUbhxldEFmvJ5lRr9+vQbpuh+RKf/oGCjp/ljKot4U5akWCF0sku2Tu8UFSa TZEwWVOERuX0RqnUoF6bioqM8/D0vSuceZi6/9TLer9rgKMarUk4LPjJ7fHINWJgccsp iDtCJbyBOHFWMJm0zgnp7BHg5ZxhP9WTNWADpPh6UBINXbWy7marRKt24xGi2C1pzCDy qEoiVK/VuFh0DLQLlwljJhrVuwkOC9fAIHit7CBEIvUZmItJf8iaC/n15WMJUelboU51 L6Rfc0Y2+KUI1RN0p2O5ZsHs42X7ct3EQ63YeRg4OndG4CRdfTMNhrFvobwn3c4ZTaeC d00w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ecJP7v0oRCLhCurZ0JCd/wOq7qAmE5n78Mx0IuOYNps=; b=UmfXr9TGFsBEpOKcWjTnRDUf+F80Tl+it38lH6DZd/l6Npowdl7637TkhnW/KOG/bl sqlWAD1sDIE+jcBO+z/YlJaf8Ye6+8YrdNBl8Zb9UKbMTW+Et0QBzTT/qpATRVEc8ACW RTQfMV3xR5z3COxgFDyqF42cDUKOww76xrnZYAvtNW4tq6AOytw8KIcKqt0W2AcUB8Vu KhL0d1YDpP8V7RMG0F5WMi52DLSkQmIEMSX1fo0NbtCGqUyq5En89jIxce2DFQJ+3bzJ 0yOJLFYZSdlgHWzBbSgLaP2b3FpJd9rYW9x/rRSOTipZQb8p2SA5KPc50XWXaCFawCEz F0jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aPa9gdbm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g10si8519529ejt.549.2021.07.15.12.38.43; Thu, 15 Jul 2021 12:39:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aPa9gdbm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343906AbhGOTe3 (ORCPT + 99 others); Thu, 15 Jul 2021 15:34:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:50994 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243169AbhGOTLW (ORCPT ); Thu, 15 Jul 2021 15:11:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3032B613C4; Thu, 15 Jul 2021 19:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626376103; bh=HGekkCC/ze57AUR8GofCif+vLEiHASe+rnbp3h+2LsA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aPa9gdbmX2t1AzHCw2VhrXYnqnuzgO4It1wmYqTeFs2hJLGsO25jFHFQg5Ec5+p2A Zh28839QpWnz51JuPdqAb5I8OLWZqv2dF6CTv0KTKy2SkLat5iblkID/SKXYALFosJ sAPGTplxNbfw4X8rxyJT/ibfRO5FxcZmAoe8QvaU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pascal Terjan , Kalle Valo , Sasha Levin Subject: [PATCH 5.13 129/266] rtl8xxxu: Fix device info for RTL8192EU devices Date: Thu, 15 Jul 2021 20:38:04 +0200 Message-Id: <20210715182636.610984775@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182613.933608881@linuxfoundation.org> References: <20210715182613.933608881@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pascal Terjan [ Upstream commit c240b044edefa3c3af4014a4030e017dd95b59a1 ] Based on 2001:3319 and 2357:0109 which I used to test the fix and 0bda:818b and 2357:0108 for which I found efuse dumps online. == 2357:0109 == === Before === Vendor: Realtek Product: \x03802.11n NI Serial: === After === Vendor: Realtek Product: 802.11n NIC Serial not available. == 2001:3319 == === Before === Vendor: Realtek Product: Wireless N Serial: no USB Adap === After === Vendor: Realtek Product: Wireless N Nano USB Adapter Serial not available. Signed-off-by: Pascal Terjan Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/20210424172959.1559890-1-pterjan@google.com Signed-off-by: Sasha Levin --- .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 11 +--- .../realtek/rtl8xxxu/rtl8xxxu_8192e.c | 59 +++++++++++++++++-- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h index d1a566cc0c9e..01735776345a 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h @@ -853,15 +853,10 @@ struct rtl8192eu_efuse { u8 usb_optional_function; u8 res9[2]; u8 mac_addr[ETH_ALEN]; /* 0xd7 */ - u8 res10[2]; - u8 vendor_name[7]; - u8 res11[2]; - u8 device_name[0x0b]; /* 0xe8 */ - u8 res12[2]; - u8 serial[0x0b]; /* 0xf5 */ - u8 res13[0x30]; + u8 device_info[80]; + u8 res11[3]; u8 unknown[0x0d]; /* 0x130 */ - u8 res14[0xc3]; + u8 res12[0xc3]; }; struct rtl8xxxu_reg8val { diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c index cfe2dfdae928..b06508d0cdf8 100644 --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8192e.c @@ -554,9 +554,43 @@ rtl8192e_set_tx_power(struct rtl8xxxu_priv *priv, int channel, bool ht40) } } +static void rtl8192eu_log_next_device_info(struct rtl8xxxu_priv *priv, + char *record_name, + char *device_info, + unsigned int *record_offset) +{ + char *record = device_info + *record_offset; + + /* A record is [ total length | 0x03 | value ] */ + unsigned char l = record[0]; + + /* + * The whole device info section seems to be 80 characters, make sure + * we don't read further. + */ + if (*record_offset + l > 80) { + dev_warn(&priv->udev->dev, + "invalid record length %d while parsing \"%s\" at offset %u.\n", + l, record_name, *record_offset); + return; + } + + if (l >= 2) { + char value[80]; + + memcpy(value, &record[2], l - 2); + value[l - 2] = '\0'; + dev_info(&priv->udev->dev, "%s: %s\n", record_name, value); + *record_offset = *record_offset + l; + } else { + dev_info(&priv->udev->dev, "%s not available.\n", record_name); + } +} + static int rtl8192eu_parse_efuse(struct rtl8xxxu_priv *priv) { struct rtl8192eu_efuse *efuse = &priv->efuse_wifi.efuse8192eu; + unsigned int record_offset; int i; if (efuse->rtl_id != cpu_to_le16(0x8129)) @@ -604,12 +638,25 @@ static int rtl8192eu_parse_efuse(struct rtl8xxxu_priv *priv) priv->has_xtalk = 1; priv->xtalk = priv->efuse_wifi.efuse8192eu.xtal_k & 0x3f; - dev_info(&priv->udev->dev, "Vendor: %.7s\n", efuse->vendor_name); - dev_info(&priv->udev->dev, "Product: %.11s\n", efuse->device_name); - if (memchr_inv(efuse->serial, 0xff, 11)) - dev_info(&priv->udev->dev, "Serial: %.11s\n", efuse->serial); - else - dev_info(&priv->udev->dev, "Serial not available.\n"); + /* + * device_info section seems to be laid out as records + * [ total length | 0x03 | value ] so: + * - vendor length + 2 + * - 0x03 + * - vendor string (not null terminated) + * - product length + 2 + * - 0x03 + * - product string (not null terminated) + * Then there is one or 2 0x00 on all the 4 devices I own or found + * dumped online. + * As previous version of the code handled an optional serial + * string, I now assume there may be a third record if the + * length is not 0. + */ + record_offset = 0; + rtl8192eu_log_next_device_info(priv, "Vendor", efuse->device_info, &record_offset); + rtl8192eu_log_next_device_info(priv, "Product", efuse->device_info, &record_offset); + rtl8192eu_log_next_device_info(priv, "Serial", efuse->device_info, &record_offset); if (rtl8xxxu_debug & RTL8XXXU_DEBUG_EFUSE) { unsigned char *raw = priv->efuse_wifi.raw; -- 2.30.2