Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp72864yba; Mon, 1 Apr 2019 01:57:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqzCQOKVL+LP7/X6JMdZc4VTDyFXKPvGsqvmgPpTyeHw6zeAcY5CETTvyuS0sjVGlWWCjInJ X-Received: by 2002:a17:902:2963:: with SMTP id g90mr63610852plb.182.1554109071932; Mon, 01 Apr 2019 01:57:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554109071; cv=none; d=google.com; s=arc-20160816; b=k/KdbcW5NqIBLpk1MZ+UrlZ7cpx76i9N0u7strtG6z5mq5Mkev8fOSVaqDIqn/2Lh+ msL365pH09MOFsATbIglMlTZRXT6DEQsfXRJZVOyseSw/wxJm8CWzEiaDrFg/GU3KTVj /IP6v2KbDsK58ORP+VhMm5jBiO+cSiVZSv9ZEn7LeooyHRTtlvz+doIJeL1uUlDs7mo5 p9VzPl7waiEOgBRPoO2VgynDzdL5mBAtq63cuJBHm/eDf9hidIf0lFYF0vkvZ1LxmWTb HByx49aHFbF6+FVeIkjqfYsbvEIM4V9iRkZKjUtUxS01zoUFIskwrZiCsG1JyFOXc2/u 5WIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=FxqTtDEuf+MeBwWF5a9WucbR/Mh6Zg0VE+1qP66wU2c=; b=LHYpCB0fFfuO33WjPwshMoVcZyWDdLo4BZSgEiFU50skNNFTxOBwodCt168/68AB6w HFMyuIsyJR6AwNyySt+u7Q2M3UlAkd5FACypN5d+Sufbdbwh9aM3mffwYwlTUNVWjoKC 8rUSjkkxqwSlC/TDcNkaL72IPjt7RL+i6M4w4IWTW7EG5FK0DVKXYd/WNn5WIlfHdY8u V+4sHSFZSUpPPDGq42KIszWTId1SlUBqT77KRi/J6B07kYAHcd/7zYIsjkpb9pLKlrSF v3XVd8npXLFWfb3lVr0cfxZQtxWtaXt6VJuw66n+xeRPfGc4S7Rg565zrVqbmA4V5HgJ VZyg== ARC-Authentication-Results: i=1; mx.google.com; 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 n129si1939669pgn.580.2019.04.01.01.57.36; Mon, 01 Apr 2019 01:57:51 -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; 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 S1728591AbfDAI47 (ORCPT + 99 others); Mon, 1 Apr 2019 04:56:59 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:10110 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726592AbfDAI47 (ORCPT ); Mon, 1 Apr 2019 04:56:59 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x318ueKm028593; Mon, 1 Apr 2019 10:56:50 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2rhy3x9has-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 01 Apr 2019 10:56:50 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id E90BA48; Mon, 1 Apr 2019 08:56:49 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas22.st.com [10.75.90.92]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 62F1116BA; Mon, 1 Apr 2019 08:56:18 +0000 (GMT) Received: from SAFEX1HUBCAS23.st.com (10.75.90.47) by Safex1hubcas22.st.com (10.75.90.92) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 1 Apr 2019 10:56:18 +0200 Received: from localhost (10.201.23.19) by webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.435.0; Mon, 1 Apr 2019 10:56:17 +0200 From: Hugues Fruchet To: Alexandre Torgue , Mauro Carvalho Chehab , Hans Verkuil CC: , , , , Benjamin Gaignard , Yannick Fertre , Philippe CORNU , "Hugues Fruchet" Subject: [PATCH] media: stm32-dcmi: fix crash when subdev do not expose any formats Date: Mon, 1 Apr 2019 10:56:09 +0200 Message-ID: <1554108969-30771-1-git-send-email-hugues.fruchet@st.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.201.23.19] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-04-01_04:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 b63d57c..906e71b 100644 --- a/drivers/media/platform/stm32/stm32-dcmi.c +++ b/drivers/media/platform/stm32/stm32-dcmi.c @@ -831,6 +831,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; } @@ -1009,6 +1012,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.7.4