spi/pl022: fix dubious allocation staticize platform data

This removes some dubious allocation of a local chipinfo struct
in favor of a constant preset, tagging that one const revealed
further problems with platform data being modified so fixed up
these too.

Reported-by: Virupax Sadashivpetimath <virupax.sadashivpetimath@stericsson.com>
Signed-off-by: Linus Walleij <linus.walleij@stericsson.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

authored by

Linus Walleij and committed by
Grant Likely
f9d629c7 5a1c98be

+46 -50
+46 -50
drivers/spi/amba-pl022.c
··· 1593 1593 } 1594 1594 1595 1595 static int verify_controller_parameters(struct pl022 *pl022, 1596 - struct pl022_config_chip *chip_info) 1596 + struct pl022_config_chip const *chip_info) 1597 1597 { 1598 1598 if ((chip_info->iface < SSP_INTERFACE_MOTOROLA_SPI) 1599 1599 || (chip_info->iface > SSP_INTERFACE_UNIDIRECTIONAL)) { ··· 1612 1612 && (chip_info->hierarchy != SSP_SLAVE)) { 1613 1613 dev_err(&pl022->adev->dev, 1614 1614 "hierarchy is configured incorrectly\n"); 1615 - return -EINVAL; 1616 - } 1617 - if (((chip_info->clk_freq).cpsdvsr < CPSDVR_MIN) 1618 - || ((chip_info->clk_freq).cpsdvsr > CPSDVR_MAX)) { 1619 - dev_err(&pl022->adev->dev, 1620 - "cpsdvsr is configured incorrectly\n"); 1621 1615 return -EINVAL; 1622 1616 } 1623 1617 if ((chip_info->com_mode != INTERRUPT_TRANSFER) ··· 1664 1670 " ST version of PL022\n"); 1665 1671 return -EINVAL; 1666 1672 } 1667 - } 1668 - if (chip_info->cs_control == NULL) { 1669 - dev_warn(&pl022->adev->dev, 1670 - "Chip Select Function is NULL for this chip\n"); 1671 - chip_info->cs_control = null_cs_control; 1672 1673 } 1673 1674 return 0; 1674 1675 } ··· 1764 1775 return 0; 1765 1776 } 1766 1777 1778 + 1779 + /* 1780 + * A piece of default chip info unless the platform 1781 + * supplies it. 1782 + */ 1783 + static const struct pl022_config_chip pl022_default_chip_info = { 1784 + .com_mode = POLLING_TRANSFER, 1785 + .iface = SSP_INTERFACE_MOTOROLA_SPI, 1786 + .hierarchy = SSP_SLAVE, 1787 + .slave_tx_disable = DO_NOT_DRIVE_TX, 1788 + .rx_lev_trig = SSP_RX_1_OR_MORE_ELEM, 1789 + .tx_lev_trig = SSP_TX_1_OR_MORE_EMPTY_LOC, 1790 + .ctrl_len = SSP_BITS_8, 1791 + .wait_state = SSP_MWIRE_WAIT_ZERO, 1792 + .duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX, 1793 + .cs_control = null_cs_control, 1794 + }; 1795 + 1796 + 1767 1797 /** 1768 1798 * pl022_setup - setup function registered to SPI master framework 1769 1799 * @spi: spi device which is requesting setup ··· 1797 1789 */ 1798 1790 static int pl022_setup(struct spi_device *spi) 1799 1791 { 1800 - struct pl022_config_chip *chip_info; 1792 + struct pl022_config_chip const *chip_info; 1801 1793 struct chip_data *chip; 1794 + struct ssp_clock_params clk_freq; 1802 1795 int status = 0; 1803 1796 struct pl022 *pl022 = spi_master_get_devdata(spi->master); 1804 1797 unsigned int bits = spi->bits_per_word; ··· 1826 1817 chip_info = spi->controller_data; 1827 1818 1828 1819 if (chip_info == NULL) { 1820 + chip_info = &pl022_default_chip_info; 1829 1821 /* spi_board_info.controller_data not is supplied */ 1830 1822 dev_dbg(&spi->dev, 1831 1823 "using default controller_data settings\n"); 1832 - 1833 - chip_info = 1834 - kzalloc(sizeof(struct pl022_config_chip), GFP_KERNEL); 1835 - 1836 - if (!chip_info) { 1837 - dev_err(&spi->dev, 1838 - "cannot allocate controller data\n"); 1839 - status = -ENOMEM; 1840 - goto err_first_setup; 1841 - } 1842 - 1843 - dev_dbg(&spi->dev, "allocated memory for controller data\n"); 1844 - 1845 - /* 1846 - * Set controller data default values: 1847 - * Polling is supported by default 1848 - */ 1849 - chip_info->com_mode = POLLING_TRANSFER; 1850 - chip_info->iface = SSP_INTERFACE_MOTOROLA_SPI; 1851 - chip_info->hierarchy = SSP_SLAVE; 1852 - chip_info->slave_tx_disable = DO_NOT_DRIVE_TX; 1853 - chip_info->rx_lev_trig = SSP_RX_1_OR_MORE_ELEM; 1854 - chip_info->tx_lev_trig = SSP_TX_1_OR_MORE_EMPTY_LOC; 1855 - chip_info->ctrl_len = SSP_BITS_8; 1856 - chip_info->wait_state = SSP_MWIRE_WAIT_ZERO; 1857 - chip_info->duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX; 1858 - chip_info->cs_control = null_cs_control; 1859 - } else { 1824 + } else 1860 1825 dev_dbg(&spi->dev, 1861 1826 "using user supplied controller_data settings\n"); 1862 - } 1863 1827 1864 1828 /* 1865 1829 * We can override with custom divisors, else we use the board ··· 1842 1860 && (0 == chip_info->clk_freq.scr)) { 1843 1861 status = calculate_effective_freq(pl022, 1844 1862 spi->max_speed_hz, 1845 - &chip_info->clk_freq); 1863 + &clk_freq); 1846 1864 if (status < 0) 1847 1865 goto err_config_params; 1848 1866 } else { 1849 - if ((chip_info->clk_freq.cpsdvsr % 2) != 0) 1850 - chip_info->clk_freq.cpsdvsr = 1851 - chip_info->clk_freq.cpsdvsr - 1; 1867 + memcpy(&clk_freq, &chip_info->clk_freq, sizeof(clk_freq)); 1868 + if ((clk_freq.cpsdvsr % 2) != 0) 1869 + clk_freq.cpsdvsr = 1870 + clk_freq.cpsdvsr - 1; 1852 1871 } 1872 + if ((clk_freq.cpsdvsr < CPSDVR_MIN) 1873 + || (clk_freq.cpsdvsr > CPSDVR_MAX)) { 1874 + dev_err(&spi->dev, 1875 + "cpsdvsr is configured incorrectly\n"); 1876 + goto err_config_params; 1877 + } 1878 + 1879 + 1853 1880 status = verify_controller_parameters(pl022, chip_info); 1854 1881 if (status) { 1855 1882 dev_err(&spi->dev, "controller data is incorrect"); 1856 1883 goto err_config_params; 1857 1884 } 1885 + 1858 1886 /* Now set controller state based on controller data */ 1859 1887 chip->xfer_type = chip_info->com_mode; 1860 - chip->cs_control = chip_info->cs_control; 1888 + if (!chip_info->cs_control) { 1889 + chip->cs_control = null_cs_control; 1890 + dev_warn(&spi->dev, 1891 + "chip select function is NULL for this chip\n"); 1892 + } else 1893 + chip->cs_control = chip_info->cs_control; 1861 1894 1862 1895 if (bits <= 3) { 1863 1896 /* PL022 doesn't support less than 4-bits */ ··· 1929 1932 SSP_DMACR_MASK_TXDMAE, 1); 1930 1933 } 1931 1934 1932 - chip->cpsr = chip_info->clk_freq.cpsdvsr; 1935 + chip->cpsr = clk_freq.cpsdvsr; 1933 1936 1934 1937 /* Special setup for the ST micro extended control registers */ 1935 1938 if (pl022->vendor->extended_cr) { ··· 1986 1989 tmp = SSP_CLK_FIRST_EDGE; 1987 1990 SSP_WRITE_BITS(chip->cr0, tmp, SSP_CR0_MASK_SPH, 7); 1988 1991 1989 - SSP_WRITE_BITS(chip->cr0, chip_info->clk_freq.scr, SSP_CR0_MASK_SCR, 8); 1992 + SSP_WRITE_BITS(chip->cr0, clk_freq.scr, SSP_CR0_MASK_SCR, 8); 1990 1993 /* Loopback is available on all versions except PL023 */ 1991 1994 if (!pl022->vendor->pl023) { 1992 1995 if (spi->mode & SPI_LOOP) ··· 2004 2007 return status; 2005 2008 err_config_params: 2006 2009 spi_set_ctldata(spi, NULL); 2007 - err_first_setup: 2008 2010 kfree(chip); 2009 2011 return status; 2010 2012 }