Skip to contentSkip to conversation

spi: sirf: request and free cs gpio in setup and cleanup callbacks

DISCUSSION Dan Carpenter 1 participant 1 message Mar 25, 2016 SPI

lore
Share & tools
lore
#0 lore raw

Hello Qipan Li,

The patch 96bf40194fdd: "spi: sirf: request and free cs gpio in setup and cleanup callbacks" from May 3, 2015, leads to the following static checker warning:

	drivers/spi/spi-sirf.c:1028 spi_sirfsoc_setup()
	error: memory leak of 'cs'

drivers/spi/spi-sirf.c
995 static int spi_sirfsoc_setup(struct spi_device *spi) 996 {
997 struct sirfsoc_spi *sspi;
998 int ret = 0;
999
1000 sspi = spi_master_get_devdata(spi->master);
1001 if (spi->cs_gpio == -ENOENT)
1002 sspi->hw_cs = true;
1003 else {
1004 sspi->hw_cs = false;
1005 if (!spi_get_ctldata(spi)) {
1006 void *cs = kmalloc(sizeof(int), GFP_KERNEL);
1007 if (!cs) {
1008 ret = -ENOMEM;
1009 goto exit;

  1010                          }
  1011                          ret = gpio_is_valid(spi->cs_gpio);
  1012                          if (!ret) {
  1013                                  dev_err(&spi->dev, "no valid gpio\n");
  1014                                  ret = -ENOENT;
  1015                                  goto exit;

kfree(cs);

  1016                          }
  1017                          ret = gpio_request(spi->cs_gpio, DRIVER_NAME);
  1018                          if (ret) {

1019 dev_err(&spi->dev, "failed to request gpio\n");
1020 goto exit;

Same.

  1021                          }
  1022                          spi_set_ctldata(spi, cs);
  1023                  }
  1024          }
  1025          spi_sirfsoc_config_mode(spi);
  1026          spi_sirfsoc_chipselect(spi, BITBANG_CS_INACTIVE);
  1027  exit:
  1028          return ret;
  1029  }

regards,
dan carpenter
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html