Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753396AbbEGJzz (ORCPT ); Thu, 7 May 2015 05:55:55 -0400 Received: from mga14.intel.com ([192.55.52.115]:6684 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753072AbbEGJuU (ORCPT ); Thu, 7 May 2015 05:50:20 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,384,1427785200"; d="scan'208";a="490499098" Message-ID: <1430992216.28073.14.camel@linux.intel.com> Subject: Re: [PATCH 3.2 108/221] spi: dw-mid: avoid potential NULL dereference From: Andy Shevchenko To: Ben Hutchings Cc: Luis Henriques , linux-kernel@vger.kernel.org, stable@vger.kernel.org, akpm@linux-foundation.org, Mark Brown Date: Thu, 07 May 2015 12:50:16 +0300 In-Reply-To: <1430927107.11698.17.camel@decadent.org.uk> References: <20150506102502.GA1691@ares.olymp> <1430927107.11698.17.camel@decadent.org.uk> Organization: Intel Finland Oy Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.12.9-1+b1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3036 Lines: 87 On Wed, 2015-05-06 at 16:45 +0100, Ben Hutchings wrote: > On Wed, 2015-05-06 at 11:25 +0100, Luis Henriques wrote: > > On Tue, May 05, 2015 at 02:16:39AM +0100, Ben Hutchings wrote: > > > 3.2.69-rc1 review patch. If anyone has any objections, please let me know. > > > > > > ------------------ > > > > > > From: Andy Shevchenko > > > > > > commit c9dafb27c84412fe4b17c3b94cc4ffeef5df1833 upstream. > > > > > > When DMA descriptor allocation fails we should not try to assign any fields in > > > the bad descriptor. The patch adds the necessary checks for that. > > > > > > Fixes: 7063c0d942a1 (spi/dw_spi: add DMA support) > > > Signed-off-by: Andy Shevchenko > > > Signed-off-by: Mark Brown > > > [bwh: Backported to 3.2: adjust context] > > > Signed-off-by: Ben Hutchings > > > --- > > > drivers/spi/spi-dw-mid.c | 6 ++++++ > > > 1 file changed, 6 insertions(+) > > > > > > --- a/drivers/spi/spi-dw-mid.c > > > +++ b/drivers/spi/spi-dw-mid.c > > > @@ -155,6 +155,9 @@ static int mid_spi_dma_transfer(struct d > > > 1, > > > DMA_TO_DEVICE, > > > DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_DEST_UNMAP); > > > + if (!txdesc) > > > + return NULL; > > > + > > > > This backport doesn't look right to me as the function returns an int, > > not a pointer. OTOH, it seems like this return value is not checked > > anywhere, which is why I dropped this patch in the 3.16 kernel. > > In mainline the DMA descriptor setup is split out into the > dw_spi_dma_prepare_tx() and dw_spi_dma_prepare_rx() functions. If they > return NULL then mid_spi_dma_transfer() doesn't attempt to submit > adescriptor to the respective channel, but it still returns 0. Seems like error handling is not good enough. I hope someone in the future can fix this (currently it looks like DMA is used on Intel SoCs only, though I have no time to amend the code). > > So not only is this backport pretty useless, but so is the upstream > 'fix'. > > Ben. > > > Cheers, > > -- > > Luís > > > > > txdesc->callback = dw_spi_dma_done; > > > txdesc->callback_param = dws; > > > > > > @@ -177,6 +180,9 @@ static int mid_spi_dma_transfer(struct d > > > 1, > > > DMA_FROM_DEVICE, > > > DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_DEST_UNMAP); > > > + if (!rxdesc) > > > + return NULL; > > > + > > > rxdesc->callback = dw_spi_dma_done; > > > rxdesc->callback_param = dws; > > > > > > > > > -- > > > To unsubscribe from this list: send the line "unsubscribe stable" in > > > the body of a message to majordomo@vger.kernel.org > > > More majordomo info at http://vger.kernel.org/majordomo-info.html > -- Andy Shevchenko Intel Finland Oy -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/