Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp238952ybi; Wed, 29 May 2019 20:25:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqyI+PRWCIpUXpMIfSj09pDcNoBYAfb8A0aDzHW4xyeEH0aTePbbpN5emfTlMBzI4O496PyY X-Received: by 2002:a62:1cd8:: with SMTP id c207mr1434225pfc.252.1559186705156; Wed, 29 May 2019 20:25:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559186705; cv=none; d=google.com; s=arc-20160816; b=R36DoyuEoznjjVYQGLP1B0sa73kYtRX82EW081T1E3oFRUvVEqJ4tyhpMkiGJ3FOBm /GwBzBagK9ZpZn4glyUJyHGs2b1xVnSR89SzylCGtXYDWPKggUJ0l0ousPMzRdE103+9 oOQF45bkBGNcy8pT+2qsasQ8PBNKbNGXT5wmC8TgJVEOEsdcC1SSHvw0JLn4OawAPY/e Im+rOq0EP5ZLTjpBDrNEsUjdliHEc+xvz/KLR9QgKhOphkjC2N73aZMbfw6uK9Fz5Ss8 tALWKXJKJHdo88Y6uwJovnxmiP9GjQ04Bazr7gMklPFhDVnUQpzfXjQDMgzLUXkm0ZL9 zG7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MMBsTaLm97ZR76Atmdpx2oUYe8CeAk12071Um8RZr1k=; b=NyAIWhlflqiClQyJCwpSrleo2KERKKV8oPv25MUTV5YTu1/WlXRT5+8cBYF0JVHlnE IyyJK2Pnelq5yBqpbF2XwEuUC44OS5eJPqk1P1Q0selQBtLrq1BDmSWU1vpk371p09k2 CAHMq1sahdQuf8lJxqxGzb0t1yNcDoID8G+/1pSDaziQjFvpMTo1dOnHV36QHZAYTge4 BYr/zfQzoYR1BAhYgHBc416/avA2mhX7Kj7JB4kPCYw35oh/rTBVrkoXGKkh2nuEK4ni vHWQ+pCG5/scgmODe62hHRjoruFJe2e748AWu62aUoaDsuUFe1xOuYhpvPlf3CvSyhL6 ObCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qNPkUt4m; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n91si2002207pjc.19.2019.05.29.20.24.48; Wed, 29 May 2019 20:25:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qNPkUt4m; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732984AbfE3DW6 (ORCPT + 99 others); Wed, 29 May 2019 23:22:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:45256 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730945AbfE3DRL (ORCPT ); Wed, 29 May 2019 23:17:11 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AB5CD24675; Thu, 30 May 2019 03:17:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186230; bh=fbaCxHUnRLz4AuJFa+gdAKEqN7yf3n1DQ2EtkJEuU4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qNPkUt4mbT6OG5QmfjaKakF8FTqBg33gkglX9cVIVNMQumUMkUeo19iwyGu8X6D4u g9z+wdR/OMcAt5YGhpAl356day+nSspHTdDdP81R9i6zVgFKAyl01hxJE8u+qkUBva 4q3ENvcSkvTcUMVGreSQgc4N1giGAx43+BqxaPdw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hugues Fruchet , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.19 126/276] media: stm32-dcmi: fix crash when subdev do not expose any formats Date: Wed, 29 May 2019 20:04:44 -0700 Message-Id: <20190530030533.698018133@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030523.133519668@linuxfoundation.org> References: <20190530030523.133519668@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 33dfeb62e23c31619d2197850f7e8b50e8cc5466 ] Do not access sd_formats[] if num_of_sd_formats is zero, ie subdev sensor didn't expose any formats. Signed-off-by: Hugues Fruchet Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/platform/stm32/stm32-dcmi.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/media/platform/stm32/stm32-dcmi.c b/drivers/media/platform/stm32/stm32-dcmi.c index 100a5922d75fd..d386822658922 100644 --- a/drivers/media/platform/stm32/stm32-dcmi.c +++ b/drivers/media/platform/stm32/stm32-dcmi.c @@ -808,6 +808,9 @@ static int dcmi_try_fmt(struct stm32_dcmi *dcmi, struct v4l2_format *f, sd_fmt = find_format_by_fourcc(dcmi, pix->pixelformat); if (!sd_fmt) { + if (!dcmi->num_of_sd_formats) + return -ENODATA; + sd_fmt = dcmi->sd_formats[dcmi->num_of_sd_formats - 1]; pix->pixelformat = sd_fmt->fourcc; } @@ -986,6 +989,9 @@ static int dcmi_set_sensor_format(struct stm32_dcmi *dcmi, sd_fmt = find_format_by_fourcc(dcmi, pix->pixelformat); if (!sd_fmt) { + if (!dcmi->num_of_sd_formats) + return -ENODATA; + sd_fmt = dcmi->sd_formats[dcmi->num_of_sd_formats - 1]; pix->pixelformat = sd_fmt->fourcc; } -- 2.20.1