On Wed, Dec 16, 2020 at 09:25:47AM +0100, Jiri Slaby wrote:
> On 15. 12. 20, 19:15, József Horváth wrote:
> > --- /dev/null
> > +++ b/drivers/tty/serial/si4455.c
> > @@ -0,0 +1,1372 @@
> ...
> > +static int si4455_write_data(struct uart_port *port, u8 command, int poll,
> > +                        int length, const u8 *data)
> > +{
> > +   int ret = 0;
> > +   u8 *data_out;
> > +
> > +   if (poll) {
> > +           ret = si4455_poll_cts(port);
> > +           if (ret)
> > +                   return ret;
> > +   }
> > +
> > +   data_out = kzalloc(1 + length, GFP_KERNEL);
> > +   if (!data_out)
> > +           return -ENOMEM;
> > +
> > +   data_out[0] = command;
> > +   memcpy(&data_out[1], data, length);
> > +   ret = spi_write(to_spi_device(port->dev), data_out, 1 + length);
> > +   if (ret) {
> > +           dev_err(port->dev,
> > +                   "%s: spi_write error (%i)\n", __func__, ret);
> > +   }
> > +
> > +   kfree(data_out);
> > +
> > +   return ret;
> > +}
> > +
> > +static void si4455_set_power(struct si4455_port *priv, int on)
> 
> "on" can be bool here. And "poll" in earlier functions. And "on" in later
> ones.
> 
> > +{
> > +   if (!priv->shdn_gpio)
> > +           return;
> > +   if (on) {
> > +           gpiod_direction_output(priv->shdn_gpio, 0);
> > +           usleep_range(4000, 5000);
> > +           gpiod_set_value(priv->shdn_gpio, 1);
> > +           usleep_range(4000, 5000);
> > +   } else {
> > +           gpiod_direction_output(priv->shdn_gpio, 0);
> > +   }
> 
> The above can be simpler:
> 
> gpiod_direction_output(priv->shdn_gpio, 0);
> 
> if (on) {
>       usleep_range(4000, 5000);
>       gpiod_set_value(priv->shdn_gpio, 1);
>       usleep_range(4000, 5000);
> }
> 
> > +static void si4455_handle_rx_pend(struct si4455_port *s)
> > +{
> > +   struct uart_port *port = &s->port;
> > +   u8 *data = NULL;
> 
> Unused initialization.
> 
> > +   int sret = 0;
> > +   int i = 0;
> > +
> > +   if (s->package_size == 0) {
> > +           //TODO: variable packet length
> > +           dev_err(port->dev, "%s: variable packet length is not supported 
> > by the driver\n",
> > +                   __func__);
> > +           return;
> > +   }
> > +
> > +   data = kzalloc(s->package_size, GFP_KERNEL);
> 
> Missing check of data.
> 
> > +   sret = si4455_end_rx(port, s->package_size, data);
> > +   if (sret) {
> > +           dev_err(port->dev, "%s: si4455_end_rx error (%i)\n",
> > +                   __func__, sret);
> > +   } else {
> > +           for (i = 0; i < s->package_size; i++) {
> > +                   uart_insert_char(port, 0, 0, data[i], TTY_NORMAL);
> > +                   port->icount.rx++;
> > +           }
> > +           tty_flip_buffer_push(&port->state->port);
> > +   }
> > +   kfree(data);
> > +}
> ...
> thanks,
> -- 
> js
> suse labs

Thank you for suggestions.

Üdvözlettel / Best regards:
József Horváth

Reply via email to