From patchwork Fri Aug 17 18:15:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Sealey X-Patchwork-Id: 178293 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 0C51D2C00A4 for ; Sat, 18 Aug 2012 04:15:56 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 660F92833D; Fri, 17 Aug 2012 20:15:54 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PGw4zfV-0zBw; Fri, 17 Aug 2012 20:15:54 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 224AC2832E; Fri, 17 Aug 2012 20:15:52 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 555432832E for ; Fri, 17 Aug 2012 20:15:50 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id X92CJDHQd2XY for ; Fri, 17 Aug 2012 20:15:49 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-yw0-f44.google.com (mail-yw0-f44.google.com [209.85.213.44]) by theia.denx.de (Postfix) with ESMTPS id 81C1628327 for ; Fri, 17 Aug 2012 20:15:47 +0200 (CEST) Received: by yhq56 with SMTP id 56so4751461yhq.3 for ; Fri, 17 Aug 2012 11:15:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=1wgE1h7cHFmBz6IaJUK5EXhjNILK8B4E/lXu1nZ2QCo=; b=VPfDD08cuLeYHaPD5AlJ0PvQBhH5FvegLf/wyG0q0HMJcw5Eg72IGuRGfW1rDR0Z+O H8uXDPlhg4IjOKvyPmIoYBaFsIki3zjOOvqPehzGveaL+/dwVJeytWkSGhmFa7BCfUiR c3z2XsWZnNZClWLKkNebQonrMy+7e758EqpsgU8FoPsN5GMD+pyz+ta3oIVX8WdpPo7C VsIDbZ8fdWNvDOaYWpRs7Xc0XWDxuR1uEoEXry4t9D0/BKD2wQmxyr835WIOrmyY55iU yaxxi7gF1yMh9z5/37Wv1fh9v0lmny/FuXcywPC9WOeRk4JQEKP4qWpdCBpeVYk1llCl u8wg== Received: by 10.60.169.100 with SMTP id ad4mr4742404oec.21.1345227346918; Fri, 17 Aug 2012 11:15:46 -0700 (PDT) Received: from shinji.genesi-usa.com ([199.193.222.22]) by mx.google.com with ESMTPS id j10sm5348594oej.10.2012.08.17.11.15.46 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 17 Aug 2012 11:15:46 -0700 (PDT) From: Matt Sealey To: U-Boot ML Date: Fri, 17 Aug 2012 13:15:10 -0500 Message-Id: <1345227311-11433-1-git-send-email-matt@genesi-usa.com> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQnlqTUCUHiMTmKmo7DKU4eq2syI3sDoEO5qw1c4BmIXoh8oVoBrVyVRk4b1PSI4bTk4YhQK Cc: Steev Klimaszewski Subject: [U-Boot] [PATCH 1/2] spi: fix mxc_spi_slave structure allocation to clear memory X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Use calloc() instead of malloc() to allocate the mxc_spi_slave structure. Clearing the memory is necessary since most of the time this gets done super early in boot, but on warm reboots, and when SPI probing is done long after the init stages it could actually pick up previously used memory, and things like the chipselect polarity and other data end up being filled with trash data if not explicitly set by the board files. This solves a semi-random, almost unreproducable error whereby SPI devices act very, very strangly on boot. Tested on Efika MX over several years.. Signed-off-by: Matt Sealey Acked-by: Stefano Babic --- drivers/spi/mxc_spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/mxc_spi.c b/drivers/spi/mxc_spi.c index 2e15318..d1dab18 100644 --- a/drivers/spi/mxc_spi.c +++ b/drivers/spi/mxc_spi.c @@ -408,7 +408,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, if (bus >= ARRAY_SIZE(spi_bases)) return NULL; - mxcs = malloc(sizeof(struct mxc_spi_slave)); + mxcs = calloc(sizeof(struct mxc_spi_slave), 1); if (!mxcs) { puts("mxc_spi: SPI Slave not allocated !\n"); return NULL;