From: Mike Frysinger Date: Wed, 6 Jan 2010 13:51:44 -0500 Subject: [U-Boot] [PATCH v4] TI DaVinci: Driver for the davinci SPI controller In-Reply-To: <1262776701-22572-1-git-send-email-sudhakar.raj@ti.com> References: <1262776701-22572-1-git-send-email-sudhakar.raj@ti.com> Message-ID: <201001061351.47797.vapier@gentoo.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Wednesday 06 January 2010 06:18:21 Sudhakar Rajashekhara wrote: > + ds = malloc(sizeof(struct davinci_spi_slave)); personally i find sizeof(*ds) to be better > +void spi_free_slave(struct spi_slave *slave) > +{ > + struct davinci_spi_slave *ds = to_davinci_spi(slave); > + > + if (ds) { > + free(ds); > + ds = NULL; > + } > +} free() already does a NULL pointer check, and assigning NULL to a stack variable is pointless. i.e. this function should simply be: free(slave); > +static inline struct davinci_spi_slave *to_davinci_spi(struct spi_slave > *slave) +{ > + if (!slave) > + return NULL; > + else > + return container_of(slave, struct davinci_spi_slave, slave); > +} this logic is pointless ... container_of() on a NULL pointer is a NULL pointer, and it isnt like container_of() will deref the pointer causing a crash. -mike -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part. Url : http://lists.denx.de/pipermail/u-boot/attachments/20100106/57529085/attachment.pgp