[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2024081350-tingly-coming-a74d@gregkh>
Date: Tue, 13 Aug 2024 11:33:47 +0200
From: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To: Vadim Fedorenko <vadfed@...a.com>
Cc: Vadim Fedorenko <vadim.fedorenko@...ux.dev>,
Jakub Kicinski <kuba@...nel.org>,
Jonathan Lemon <jonathan.lemon@...il.com>,
Jiri Slaby <jirislaby@...nel.org>, netdev@...r.kernel.org
Subject: Re: [PATCH net v2 1/2] ptp: ocp: adjust sysfs entries to expose tty
information
On Mon, Aug 05, 2024 at 03:04:59PM -0700, Vadim Fedorenko wrote:
> Starting v6.8 the serial port subsystem changed the hierarchy of devices
> and symlinks are not working anymore. Previous discussion made it clear
> that the idea of symlinks for tty devices was wrong by design. Implement
> additional attributes to expose the information. Fixes tag points to the
> commit which introduced the change.
>
> Fixes: b286f4e87e32 ("serial: core: Move tty and serdev to be children of serial core port device")
> Signed-off-by: Vadim Fedorenko <vadfed@...a.com>
> ---
> drivers/ptp/ptp_ocp.c | 68 +++++++++++++++++++++++++++++++++----------
> 1 file changed, 52 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index ee2ced88ab34..7a5026656452 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -3346,6 +3346,55 @@ static EXT_ATTR_RO(freq, frequency, 1);
> static EXT_ATTR_RO(freq, frequency, 2);
> static EXT_ATTR_RO(freq, frequency, 3);
>
> +static ssize_t
> +ptp_ocp_tty_show(struct device *dev, struct device_attribute *attr, char *buf)
> +{
> + struct dev_ext_attribute *ea = to_ext_attr(attr);
> + struct ptp_ocp *bp = dev_get_drvdata(dev);
> + struct ptp_ocp_serial_port *port;
> +
> + port = (void *)((uintptr_t)bp + (uintptr_t)ea->var);
That's insane pointer math, how do we know this is correct?
> + return sysfs_emit(buf, "ttyS%d", port->line);
> +}
> +
> +static umode_t
> +ptp_ocp_timecard_tty_is_visible(struct kobject *kobj, struct attribute *attr, int n)
> +{
> + struct ptp_ocp *bp = dev_get_drvdata(kobj_to_dev(kobj));
> + struct ptp_ocp_serial_port *port;
> + struct device_attribute *dattr;
> + struct dev_ext_attribute *ea;
> +
> + if (strncmp(attr->name, "tty", 3))
> + return attr->mode;
> +
> + dattr = container_of(attr, struct device_attribute, attr);
> + ea = container_of(dattr, struct dev_ext_attribute, attr);
> + port = (void *)((uintptr_t)bp + (uintptr_t)ea->var);
That's crazy pointer math, how are you ensured that it is correct? Why
isn't there a container_of() thing here instead?
thanks,
greg k-h
Powered by blists - more mailing lists