netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Franklin Lin <franklin_lin@wistron.corp-partner.google.com>
Cc: edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	linux-usb@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, davem@davemloft.net,
	franklin_lin@wistron.com
Subject: Re: [PATCH] drivers/net/usb/r8152: Enable MAC address passthru support
Date: Tue, 28 Jun 2022 07:42:34 +0200	[thread overview]
Message-ID: <YrqUyvS1OVSTIvvP@kroah.com> (raw)
In-Reply-To: <20220628015325.1204234-1-franklin_lin@wistron.corp-partner.google.com>

On Tue, Jun 28, 2022 at 09:53:25AM +0800, Franklin Lin wrote:
> From: franklin_lin <franklin_lin@wistron.corp-partner.google.com>
> 
> Enable the support for providing a MAC address
> for a dock to use based on the VPD values set in the platform.
> 
> Signed-off-by: franklin_lin <franklin_lin@wistron.corp-partner.google.com>
> ---
>  drivers/net/usb/r8152.c | 49 ++++++++++++++++++++++++++++++-----------
>  1 file changed, 36 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
> index 7389d6ef8..732e48d99 100644
> --- a/drivers/net/usb/r8152.c
> +++ b/drivers/net/usb/r8152.c
> @@ -3,6 +3,7 @@
>   *  Copyright (c) 2014 Realtek Semiconductor Corp. All rights reserved.
>   */
>  
> +#include <linux/fs.h>
>  #include <linux/signal.h>
>  #include <linux/slab.h>
>  #include <linux/module.h>
> @@ -1608,6 +1609,11 @@ static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa)
>  	acpi_object_type mac_obj_type;
>  	int mac_strlen;
>  
> +	struct file *fp;
> +	unsigned char read_buf[32];
> +	loff_t f_pos = 0;
> +	int i, j, len;
> +
>  	if (tp->lenovo_macpassthru) {
>  		mac_obj_name = "\\MACA";
>  		mac_obj_type = ACPI_TYPE_STRING;
> @@ -1641,22 +1647,39 @@ static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa)
>  	/* returns _AUXMAC_#AABBCCDDEEFF# */
>  	status = acpi_evaluate_object(NULL, mac_obj_name, NULL, &buffer);
>  	obj = (union acpi_object *)buffer.pointer;
> -	if (!ACPI_SUCCESS(status))
> -		return -ENODEV;
> -	if (obj->type != mac_obj_type || obj->string.length != mac_strlen) {
> -		netif_warn(tp, probe, tp->netdev,
> +	if (ACPI_SUCCESS(status)) {
> +		if (obj->type != mac_obj_type || obj->string.length != mac_strlen) {
> +			netif_warn(tp, probe, tp->netdev,
>  			   "Invalid buffer for pass-thru MAC addr: (%d, %d)\n",
>  			   obj->type, obj->string.length);
> -		goto amacout;
> -	}
> -
> -	if (strncmp(obj->string.pointer, "_AUXMAC_#", 9) != 0 ||
> -	    strncmp(obj->string.pointer + 0x15, "#", 1) != 0) {
> -		netif_warn(tp, probe, tp->netdev,
> -			   "Invalid header when reading pass-thru MAC addr\n");
> -		goto amacout;
> +			goto amacout;
> +		}
> +		if (strncmp(obj->string.pointer, "_AUXMAC_#", 9) != 0 ||
> +			strncmp(obj->string.pointer + 0x15, "#", 1) != 0) {
> +			netif_warn(tp, probe, tp->netdev,
> +				"Invalid header when reading pass-thru MAC addr\n");
> +			goto amacout;
> +		}
> +		ret = hex2bin(buf, obj->string.pointer + 9, 6);
> +	} else {
> +		/* read from "/sys/firmware/vpd/ro/dock_mac" */
> +		fp = filp_open("/sys/firmware/vpd/ro/dock_mac", O_RDONLY, 0);

Woah, what?  No, that's not how firmware works at all, sorry.  Please
use the correct firmware interface if this really is firmware.  If it is
not, please use the correct networking interface instead.

you should NEVER read from a file from a driver, that is a sure sign
something is really really wrong.

thanks,

greg k-h

  parent reply	other threads:[~2022-06-28  5:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-28  1:53 [PATCH] drivers/net/usb/r8152: Enable MAC address passthru support Franklin Lin
2022-06-28  5:41 ` Greg KH
2022-06-28  5:42 ` Greg KH [this message]
2022-06-28 10:17 ` Andrew Lunn
2022-06-28 11:26   ` Oliver Neukum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YrqUyvS1OVSTIvvP@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=franklin_lin@wistron.com \
    --cc=franklin_lin@wistron.corp-partner.google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).