public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Bjorn Andersson <andersson@kernel.org>
Cc: Viken Dadhaniya <quic_vdadhani@quicinc.com>,
	jirislaby@kernel.org, johan+linaro@kernel.org,
	dianders@chromium.org, konradybcio@kernel.org,
	linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-serial@vger.kernel.org, quic_msavaliy@quicinc.com,
	quic_anupkulk@quicinc.com
Subject: Re: [PATCH v1] serial: qcom-geni: Remove alias dependency from qcom serial driver
Date: Fri, 7 Mar 2025 07:52:39 +0100	[thread overview]
Message-ID: <2025030758-efficient-pledge-ba4c@gregkh> (raw)
In-Reply-To: <tn6czifetdf2mg5gl3mhfpwcb6q7dkn5r4kgqln6evm4qdsjvi@ehpl3qj3axvw>

On Tue, Mar 04, 2025 at 11:45:53AM -0600, Bjorn Andersson wrote:
> On Tue, Mar 04, 2025 at 12:44:23PM +0530, Viken Dadhaniya wrote:
> > Remove the dependency on aliases in the device tree configuration for the
> > qcom serial driver. Currently, the absence of an alias results in an
> > invalid line number, causing the driver probe to fail for geni serial.
> > 
> > To prevent probe failures, implement logic to dynamically assign line
> > numbers if an alias is not present in the device tree for non-console
> > ports.
> > 
> 
> Please read and follow https://docs.kernel.org/process/submitting-patches.html#describe-your-changes
> 
> Start with your problem description, then a description of your proposed
> solution.
> 
> > Signed-off-by: Viken Dadhaniya <quic_vdadhani@quicinc.com>
> > ---
> >  drivers/tty/serial/qcom_geni_serial.c | 26 +++++++++++++++++++++++---
> >  1 file changed, 23 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c
> > index a80ce7aaf309..2457f39dfc84 100644
> > --- a/drivers/tty/serial/qcom_geni_serial.c
> > +++ b/drivers/tty/serial/qcom_geni_serial.c
> > @@ -98,6 +98,8 @@
> >  
> >  #define DMA_RX_BUF_SIZE		2048
> >  
> > +static DEFINE_IDR(port_idr);
> 
> You're just looking for a index allocator, so DEFINE_IDA() is probably
> what you want to use.
> 
> 
> That said, theoretically I think we could get 24 GENI serial instances
> in a system. Making this a huge waste of memory and CPU cycles.
> 
> An empty idr takes 88 bytes, if you then allocate 1 entry it grows with
> at least one xa_array node which is 576 bytes.
> 
> > +
> >  struct qcom_geni_device_data {
> >  	bool console;
> >  	enum geni_se_xfer_mode mode;
> > @@ -253,10 +255,25 @@ static struct qcom_geni_serial_port *get_port_from_line(int line, bool console)
> >  	struct qcom_geni_serial_port *port;
> >  	int nr_ports = console ? GENI_UART_CONS_PORTS : GENI_UART_PORTS;
> >  
> > -	if (line < 0 || line >= nr_ports)
> > -		return ERR_PTR(-ENXIO);
> > +	if (console) {
> > +		if (line < 0 || line >= nr_ports)
> > +			return ERR_PTR(-ENXIO);
> > +
> > +		port = &qcom_geni_console_port;
> > +	} else {
> > +		int max_alias_num = of_alias_get_highest_id("serial");
> > +
> > +		if (line < 0 || line >= nr_ports)
> > +			line = idr_alloc(&port_idr, (void *)port, max_alias_num + 1, nr_ports,
> > +					 GFP_KERNEL);
> > +		else
> > +			line = idr_alloc(&port_idr, (void *)port, line, nr_ports, GFP_KERNEL);
> > +
> > +		if (line < 0)
> > +			return ERR_PTR(-ENXIO);
> >  
> > -	port = console ? &qcom_geni_console_port : &qcom_geni_uart_ports[line];
> > +		port = &qcom_geni_uart_ports[line];
> 
> Plus qcom_geni_uart_ports[] is GENI_UART_PORTS long. So you will
> actually only have a maximum of 3 ports.
> 
> 
> I like the change, but please replace port_idr with a u32 and use
> linux/bitmap.h to implement the port allocation scheme.

No, stick with an ida as that is what that is for and has the proper
locking built in, no need to "hand code" something as simple as a
numbering allocator with a bitmap.

thanks,

greg k-h

  reply	other threads:[~2025-03-07  6:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-04  7:14 [PATCH v1] serial: qcom-geni: Remove alias dependency from qcom serial driver Viken Dadhaniya
2025-03-04 17:45 ` Bjorn Andersson
2025-03-07  6:52   ` Greg KH [this message]
2025-03-27  7:12   ` Viken Dadhaniya
2025-03-05 11:10 ` kernel test robot

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=2025030758-efficient-pledge-ba4c@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=andersson@kernel.org \
    --cc=dianders@chromium.org \
    --cc=jirislaby@kernel.org \
    --cc=johan+linaro@kernel.org \
    --cc=konradybcio@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=quic_anupkulk@quicinc.com \
    --cc=quic_msavaliy@quicinc.com \
    --cc=quic_vdadhani@quicinc.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