From patchwork Fri Apr 12 10:19:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 10897887 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 10CB817E1 for ; Fri, 12 Apr 2019 10:19:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E645A2880D for ; Fri, 12 Apr 2019 10:19:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7CB228AF3; Fri, 12 Apr 2019 10:19:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D3242880D for ; Fri, 12 Apr 2019 10:19:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726881AbfDLKTo (ORCPT ); Fri, 12 Apr 2019 06:19:44 -0400 Received: from esa1.microchip.iphmx.com ([68.232.147.91]:42998 "EHLO esa1.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726327AbfDLKTn (ORCPT ); Fri, 12 Apr 2019 06:19:43 -0400 X-IronPort-AV: E=Sophos;i="5.60,340,1549954800"; d="scan'208";a="31374108" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 12 Apr 2019 03:19:42 -0700 Received: from NAM03-DM3-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.76.38) with Microsoft SMTP Server (TLS) id 14.3.352.0; Fri, 12 Apr 2019 03:19:42 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector1-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=y4kdUBe1TGQF3UjzuU9b/rLPl3rEEF1fNkuqB7xP2a0=; b=BSn34yEDO1/6yRTPf9kLpgUOqDuZY2cYpNEQHkGvhfPzmm3kb/MuH6gBIDkpU+buxMb9Q0Ghx7GpnuKq3lq9dBNYoKOXfjrM74VS1+efYj6JZPrmgm2afabLPp0FF8DN7NBijXrrVJ86ZHdm3XUQVQ1LlB4o6HBhzsbMpTSslvw= Received: from DM5PR11MB1242.namprd11.prod.outlook.com (10.168.108.8) by DM5PR11MB1947.namprd11.prod.outlook.com (10.175.88.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1792.16; Fri, 12 Apr 2019 10:19:40 +0000 Received: from DM5PR11MB1242.namprd11.prod.outlook.com ([fe80::e0e3:1d51:9e3e:6dc]) by DM5PR11MB1242.namprd11.prod.outlook.com ([fe80::e0e3:1d51:9e3e:6dc%3]) with mapi id 15.20.1792.016; Fri, 12 Apr 2019 10:19:40 +0000 From: To: , , , CC: , , , Subject: [PATCH 1/3] media: atmel: atmel-isc: limit incoming pixels per frame Thread-Topic: [PATCH 1/3] media: atmel: atmel-isc: limit incoming pixels per frame Thread-Index: AQHU8Rk9Y6GORtaCfE+2SknPF+34Og== Date: Fri, 12 Apr 2019 10:19:40 +0000 Message-ID: <1555064098-19310-2-git-send-email-eugen.hristev@microchip.com> References: <1555064098-19310-1-git-send-email-eugen.hristev@microchip.com> In-Reply-To: <1555064098-19310-1-git-send-email-eugen.hristev@microchip.com> Accept-Language: ro-RO, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR06CA0111.eurprd06.prod.outlook.com (2603:10a6:803:8c::40) To DM5PR11MB1242.namprd11.prod.outlook.com (2603:10b6:3:14::8) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Eugen.Hristev@microchip.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.7.4 x-originating-ip: [94.177.32.154] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 9eabd60a-c950-40fc-f811-08d6bf305fb8 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600139)(711020)(4605104)(2017052603328)(7193020);SRVR:DM5PR11MB1947; x-ms-traffictypediagnostic: DM5PR11MB1947: x-microsoft-antispam-prvs: x-forefront-prvs: 0005B05917 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(366004)(346002)(39860400002)(136003)(376002)(199004)(189003)(105586002)(54906003)(102836004)(36756003)(50226002)(26005)(14454004)(2906002)(97736004)(66066001)(6486002)(6436002)(6506007)(386003)(305945005)(7736002)(2501003)(81166006)(5660300002)(8676002)(446003)(8936002)(81156014)(107886003)(14444005)(256004)(486006)(4326008)(478600001)(76176011)(110136005)(106356001)(68736007)(316002)(86362001)(3846002)(71200400001)(52116002)(72206003)(2616005)(476003)(25786009)(6116002)(186003)(6512007)(71190400001)(99286004)(11346002)(2201001)(53936002);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR11MB1947;H:DM5PR11MB1242.namprd11.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: Z+3E3TIY+R1HU64aCCrGVjve05e3pHxkyUxyA/j+82JNx5abUU7qQlH71yagHm3V/jMajF1Mb4ORUCxJ9gHs4uhqm1C2Fvs03Uya51HN2kbhlKHsuQIj50kxTaFnoORwYrzrbVAvVpu83ns+l4SDCfL2yGBQcC+H6NA83FCzyFS7a/E4RJDvSaI9woRc8XHQO6JYOgwT8RNeh9/UGH3tsjwgmkMLhmDM1j+2NTI0P/zAAfbskcwGXMQ6GUF6Gjbap4EXmC2opzYqjlq+NK+rLZvSRSIAxWk9qjZrZHFzCQr/LfjW2zppsa/YQUeIFl1y9br7ElN4lJHr5P9Mds+Ig/TBhVXyvzsBkNVvp8YMElE4kPlQb3MQtL3v7vVpch6mvRpvtWfdAUrh4IRn1w3Ml8TUHw2Aa/7jPwFz7Fq03/s= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 9eabd60a-c950-40fc-f811-08d6bf305fb8 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Apr 2019 10:19:40.8490 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB1947 X-OriginatorOrg: microchip.com Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eugen Hristev This will limit the incoming pixels per frame from the sensor. Currently, the ISC will stop sampling the frame only when the vsync/hsync are detected. If we misconfigure the resolution in the sensor w.r.t. resolution in the ISC, the buffer used for DMA in the ISC will be smaller than the number of pixels that the ISC DMA engine will copy. In this case it happens that the DMA will overwrite parts of the memory which should not be written, leading to memory corruption. To avoid this situation, use the PFE CFG1 and PFE CFG2 registers, which crop the incoming frame to the resolution that we configure. This way the DMA engine will never write more data than we expect it to. Signed-off-by: Eugen Hristev --- drivers/media/platform/atmel/atmel-isc-regs.h | 19 +++++++++++++++ drivers/media/platform/atmel/atmel-isc.c | 34 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/drivers/media/platform/atmel/atmel-isc-regs.h b/drivers/media/platform/atmel/atmel-isc-regs.h index 2aadc19..768a5ad 100644 --- a/drivers/media/platform/atmel/atmel-isc-regs.h +++ b/drivers/media/platform/atmel/atmel-isc-regs.h @@ -35,6 +35,25 @@ #define ISC_PFG_CFG0_BPS_TWELVE (0x0 << 28) #define ISC_PFE_CFG0_BPS_MASK GENMASK(30, 28) +#define ISC_PFE_CFG0_COLEN BIT(12) +#define ISC_PFE_CFG0_ROWEN BIT(13) + +/* ISC Parallel Front End Configuration 1 Register */ +#define ISC_PFE_CFG1 0x00000010 + +#define ISC_PFE_CFG1_COLMIN(v) ((v)) +#define ISC_PFE_CFG1_COLMIN_MASK GENMASK(15, 0) +#define ISC_PFE_CFG1_COLMAX(v) ((v) << 16) +#define ISC_PFE_CFG1_COLMAX_MASK GENMASK(31, 16) + +/* ISC Parallel Front End Configuration 2 Register */ +#define ISC_PFE_CFG2 0x00000014 + +#define ISC_PFE_CFG2_ROWMIN(v) ((v)) +#define ISC_PFE_CFG2_ROWMIN_MASK GENMASK(15, 0) +#define ISC_PFE_CFG2_ROWMAX(v) ((v) << 16) +#define ISC_PFE_CFG2_ROWMAX_MASK GENMASK(31, 16) + /* ISC Clock Enable Register */ #define ISC_CLKEN 0x00000018 diff --git a/drivers/media/platform/atmel/atmel-isc.c b/drivers/media/platform/atmel/atmel-isc.c index a10db16..ea7520a 100644 --- a/drivers/media/platform/atmel/atmel-isc.c +++ b/drivers/media/platform/atmel/atmel-isc.c @@ -721,6 +721,40 @@ static void isc_start_dma(struct isc_device *isc) u32 sizeimage = isc->fmt.fmt.pix.sizeimage; u32 dctrl_dview; dma_addr_t addr0; + u32 h, w; + + h = isc->fmt.fmt.pix.height; + w = isc->fmt.fmt.pix.width; + + /* + * In case the sensor is not RAW, it will output a pixel (12-16 bits) + * with two samples on the ISC Data bus (which is 8-12) + * ISC will count each sample, so, we need to multiply these values + * by two, to get the real number of samples for the required pixels. + */ + if (!ISC_IS_FORMAT_RAW(isc->config.sd_format->mbus_code)) { + h <<= 1; + w <<= 1; + } + + /* + * We limit the column/row count that the ISC will output according + * to the configured resolution that we want. + * This will avoid the situation where the sensor is misconfigured, + * sending more data, and the ISC will just take it and DMA to memory, + * causing corruption. + */ + regmap_write(regmap, ISC_PFE_CFG1, + (ISC_PFE_CFG1_COLMIN(0) & ISC_PFE_CFG1_COLMIN_MASK) | + (ISC_PFE_CFG1_COLMAX(w - 1) & ISC_PFE_CFG1_COLMAX_MASK)); + + regmap_write(regmap, ISC_PFE_CFG2, + (ISC_PFE_CFG2_ROWMIN(0) & ISC_PFE_CFG2_ROWMIN_MASK) | + (ISC_PFE_CFG2_ROWMAX(h - 1) & ISC_PFE_CFG2_ROWMAX_MASK)); + + regmap_update_bits(regmap, ISC_PFE_CFG0, + ISC_PFE_CFG0_COLEN | ISC_PFE_CFG0_ROWEN, + ISC_PFE_CFG0_COLEN | ISC_PFE_CFG0_ROWEN); addr0 = vb2_dma_contig_plane_dma_addr(&isc->cur_frm->vb.vb2_buf, 0); regmap_write(regmap, ISC_DAD0, addr0); From patchwork Fri Apr 12 10:19:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 10897895 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 34B84186E for ; Fri, 12 Apr 2019 10:20:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA55228E7D for ; Fri, 12 Apr 2019 10:20:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9BD428E47; Fri, 12 Apr 2019 10:20:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0686E28E47 for ; Fri, 12 Apr 2019 10:20:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727023AbfDLKTv (ORCPT ); Fri, 12 Apr 2019 06:19:51 -0400 Received: from esa4.microchip.iphmx.com ([68.232.154.123]:60505 "EHLO esa4.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726327AbfDLKTu (ORCPT ); Fri, 12 Apr 2019 06:19:50 -0400 X-IronPort-AV: E=Sophos;i="5.60,340,1549954800"; d="scan'208";a="29792643" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES128-SHA; 12 Apr 2019 03:19:48 -0700 Received: from NAM03-DM3-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.76.37) with Microsoft SMTP Server (TLS) id 14.3.352.0; Fri, 12 Apr 2019 03:19:48 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector1-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TmfYvnqDDdveQXhLG7K4xfbnSATFnPRs+Ljzcnumuew=; b=ge+rXSdzI1M8Fln9v729V3w0IFMyPyCgZP6lgDIhxhFUlFC2rD+taLpjTCQeM+YTuIQVOtzSdO3kN0swmYKxTQC7pDC1SRgaDU8que0uymwwwKkegPQnWHuOsK05W9YDyAGNvJ/Jup/e12UBqK/6Iwo/aMRg02VtG6CsmkX67Ok= Received: from DM5PR11MB1242.namprd11.prod.outlook.com (10.168.108.8) by DM5PR11MB1947.namprd11.prod.outlook.com (10.175.88.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1792.16; Fri, 12 Apr 2019 10:19:46 +0000 Received: from DM5PR11MB1242.namprd11.prod.outlook.com ([fe80::e0e3:1d51:9e3e:6dc]) by DM5PR11MB1242.namprd11.prod.outlook.com ([fe80::e0e3:1d51:9e3e:6dc%3]) with mapi id 15.20.1792.016; Fri, 12 Apr 2019 10:19:46 +0000 From: To: , , , CC: , , , Subject: [PATCH 2/3] media: atmel: atmel-isc: fix INIT_WORK misplacement Thread-Topic: [PATCH 2/3] media: atmel: atmel-isc: fix INIT_WORK misplacement Thread-Index: AQHU8RlAswvvLxh+TkKT8iU+bXVupw== Date: Fri, 12 Apr 2019 10:19:46 +0000 Message-ID: <1555064098-19310-3-git-send-email-eugen.hristev@microchip.com> References: <1555064098-19310-1-git-send-email-eugen.hristev@microchip.com> In-Reply-To: <1555064098-19310-1-git-send-email-eugen.hristev@microchip.com> Accept-Language: ro-RO, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR06CA0111.eurprd06.prod.outlook.com (2603:10a6:803:8c::40) To DM5PR11MB1242.namprd11.prod.outlook.com (2603:10b6:3:14::8) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Eugen.Hristev@microchip.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.7.4 x-originating-ip: [94.177.32.154] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d467acd5-cc23-456c-fb92-08d6bf30633a x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600139)(711020)(4605104)(2017052603328)(7193020);SRVR:DM5PR11MB1947; x-ms-traffictypediagnostic: DM5PR11MB1947: x-microsoft-antispam-prvs: x-forefront-prvs: 0005B05917 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(366004)(346002)(39860400002)(136003)(376002)(199004)(189003)(105586002)(54906003)(102836004)(36756003)(50226002)(26005)(14454004)(2906002)(97736004)(66066001)(6486002)(6436002)(6506007)(386003)(305945005)(7736002)(2501003)(81166006)(5660300002)(8676002)(446003)(8936002)(81156014)(107886003)(256004)(486006)(4326008)(478600001)(76176011)(110136005)(106356001)(68736007)(316002)(86362001)(3846002)(71200400001)(52116002)(72206003)(2616005)(476003)(25786009)(6116002)(186003)(6512007)(71190400001)(99286004)(11346002)(2201001)(53936002);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR11MB1947;H:DM5PR11MB1242.namprd11.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: PAK1VIB696z5+4ANTKqPv7GAmGcfExry6MbeL7bn+rw5IZKiVBkiR422eShkIjwMLWMT5spDIkQRGSiBbcPWEbtsj9jUVdUL8Ur1yz3i75QxIa1Amsuk2FXSChD2AEUWTzkU63AIw4P3xyyXItrucEvkdILHxPwXTx6lW7axF/fBS9XcCuByeEICuYRRb3kpseX6Zez9RnkDcPUMH2ObKnk1kHSlSUCMrq9B6ns7Q+KqKWD+HUN0oFNDaTWK9IIdkBi5ZQQFSv9DbjTzTR67+u4bf+mHHO1WjkQzRj0MVJmj2v+I1r26PCn8RzBhYp3oiKjP8G5kUsc6XCFhMERdEL2qDGkfNN2E/Inaev3w0KyLNrGecwC1Zgxt1xD+/sJvNSUVmVZWH9irjtOLOb0UGNLn83mJVTvdwCvA2U1viPY= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: d467acd5-cc23-456c-fb92-08d6bf30633a X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Apr 2019 10:19:46.7722 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB1947 X-OriginatorOrg: microchip.com Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eugen Hristev In case the completion function failes, unbind will be called which will call cancel_work for awb_work. This will trigger a WARN message from the workqueue. To avoid this, move the INIT_WORK call at the start of the completion function. This way the work is always initialized, which corresponds to the 'always canceled' unbind code. Fixes: 93d4a26c3d ("[media] atmel-isc: add the isc pipeline function") Signed-off-by: Eugen Hristev --- drivers/media/platform/atmel/atmel-isc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/atmel/atmel-isc.c b/drivers/media/platform/atmel/atmel-isc.c index ea7520a..aef90db 100644 --- a/drivers/media/platform/atmel/atmel-isc.c +++ b/drivers/media/platform/atmel/atmel-isc.c @@ -1998,6 +1998,8 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier) struct vb2_queue *q = &isc->vb2_vidq; int ret; + INIT_WORK(&isc->awb_work, isc_awb_work); + ret = v4l2_device_register_subdev_nodes(&isc->v4l2_dev); if (ret < 0) { v4l2_err(&isc->v4l2_dev, "Failed to register subdev nodes\n"); @@ -2051,8 +2053,6 @@ static int isc_async_complete(struct v4l2_async_notifier *notifier) return ret; } - INIT_WORK(&isc->awb_work, isc_awb_work); - /* Register video device */ strscpy(vdev->name, ATMEL_ISC_NAME, sizeof(vdev->name)); vdev->release = video_device_release_empty; From patchwork Fri Apr 12 10:19:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 10897893 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E1C51669 for ; Fri, 12 Apr 2019 10:20:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF04A28E6C for ; Fri, 12 Apr 2019 10:20:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A69CD28E7C; Fri, 12 Apr 2019 10:20:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D305828ADD for ; Fri, 12 Apr 2019 10:20:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727366AbfDLKTy (ORCPT ); Fri, 12 Apr 2019 06:19:54 -0400 Received: from esa4.microchip.iphmx.com ([68.232.154.123]:60505 "EHLO esa4.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726327AbfDLKTw (ORCPT ); Fri, 12 Apr 2019 06:19:52 -0400 X-IronPort-AV: E=Sophos;i="5.60,340,1549954800"; d="scan'208";a="29792645" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 12 Apr 2019 03:19:52 -0700 Received: from NAM03-DM3-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.76.108) with Microsoft SMTP Server (TLS) id 14.3.352.0; Fri, 12 Apr 2019 03:19:51 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector1-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gdezC86ZmpzMyWPpEH1Cs31OEIomGxRPFZpAXTnUe1s=; b=ZFJS3PHUksiC1V6+CJ5ZXhoDCUF15nL9+Eo6Ti8eu2uW4szRWj9dm1UFDutmHedWN+pvBzICGhQziR9F4YxTy/4sr7WGqZ7nbzaalszPXViDXaqKUGLlCXHWsmnfYrM0Kaeo2YqauirL1nmkOV63FHcoYqAfKZE1Ut9BZTBWMhI= Received: from DM5PR11MB1242.namprd11.prod.outlook.com (10.168.108.8) by DM5PR11MB1947.namprd11.prod.outlook.com (10.175.88.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1792.16; Fri, 12 Apr 2019 10:19:50 +0000 Received: from DM5PR11MB1242.namprd11.prod.outlook.com ([fe80::e0e3:1d51:9e3e:6dc]) by DM5PR11MB1242.namprd11.prod.outlook.com ([fe80::e0e3:1d51:9e3e:6dc%3]) with mapi id 15.20.1792.016; Fri, 12 Apr 2019 10:19:50 +0000 From: To: , , , CC: , , , Subject: [PATCH 3/3] media: atmel: atmel-isc: fix asd memory allocation Thread-Topic: [PATCH 3/3] media: atmel: atmel-isc: fix asd memory allocation Thread-Index: AQHU8RlCk4yC9UUXy0av/TaU4uWanQ== Date: Fri, 12 Apr 2019 10:19:49 +0000 Message-ID: <1555064098-19310-4-git-send-email-eugen.hristev@microchip.com> References: <1555064098-19310-1-git-send-email-eugen.hristev@microchip.com> In-Reply-To: <1555064098-19310-1-git-send-email-eugen.hristev@microchip.com> Accept-Language: ro-RO, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR06CA0111.eurprd06.prod.outlook.com (2603:10a6:803:8c::40) To DM5PR11MB1242.namprd11.prod.outlook.com (2603:10b6:3:14::8) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Eugen.Hristev@microchip.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.7.4 x-originating-ip: [94.177.32.154] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e657cb9f-1ef6-4a87-7acb-08d6bf306517 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600139)(711020)(4605104)(2017052603328)(7193020);SRVR:DM5PR11MB1947; x-ms-traffictypediagnostic: DM5PR11MB1947: x-microsoft-antispam-prvs: x-forefront-prvs: 0005B05917 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(366004)(346002)(39860400002)(136003)(376002)(199004)(189003)(105586002)(54906003)(102836004)(36756003)(50226002)(26005)(14454004)(2906002)(97736004)(66066001)(6486002)(6436002)(6506007)(386003)(305945005)(7736002)(2501003)(81166006)(5660300002)(8676002)(446003)(8936002)(81156014)(107886003)(256004)(486006)(4326008)(478600001)(76176011)(110136005)(106356001)(68736007)(316002)(86362001)(3846002)(71200400001)(52116002)(72206003)(2616005)(476003)(25786009)(6116002)(186003)(6512007)(71190400001)(99286004)(11346002)(2201001)(53936002);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR11MB1947;H:DM5PR11MB1242.namprd11.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: sFSLpebleuBx3qxTxACDE21nSJeGDPuziWFjnc+8ktCZBfcCok8X1+UE8JcQ7iHNjY0MijhF0jIbDUZ7YIbok8mSmYbncL/JaDgQTf9gQTK27mGouA0fmurfG4QlgS8CTNDjpKBRQXb5PlGVi0tNiX+apeNMBi13+kD+rVJWwODzLpbu0ff65s29b8EztgM8KGxWUp6bvdMf+aW5j0TP7rsWfh20J2tzTy8QD529B/pYCaTBnWlhA2H9RhnXjzq8Gq94JefCDj6lVPGC5WnHL7D4TWbUyQVsHk7l14qx90FZ1hF6z9uXWKq9xGWP9UaZ24DkrMp8R9/urpD43SUUEgELG004yv1JMMqrNB1WWOFxdYqSbYbboJxGR3fxCvfFUSzYh2Rv1W/0lKqOwyeGb3Oi0xvPYRZ75sdQpqEo47M= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: e657cb9f-1ef6-4a87-7acb-08d6bf306517 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Apr 2019 10:19:49.9160 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB1947 X-OriginatorOrg: microchip.com Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eugen Hristev The subsystem will free the asd memory on notifier cleanup, if the asd is added to the notifier. However the memory is freed using kfree. Thus, we cannot allocate the asd using devm_* This can lead to crashes and problems. To test this issue, just return an error at probe, but cleanup the notifier beforehand. Fixes: 106267444f ("[media] atmel-isc: add the Image Sensor Controller code") Signed-off-by: Eugen Hristev --- drivers/media/platform/atmel/atmel-isc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/atmel/atmel-isc.c b/drivers/media/platform/atmel/atmel-isc.c index aef90db..8e072a9 100644 --- a/drivers/media/platform/atmel/atmel-isc.c +++ b/drivers/media/platform/atmel/atmel-isc.c @@ -2168,8 +2168,11 @@ static int isc_parse_dt(struct device *dev, struct isc_device *isc) break; } - subdev_entity->asd = devm_kzalloc(dev, - sizeof(*subdev_entity->asd), GFP_KERNEL); + /* asd will be freed by the subsystem once it's added to the + * notifier list + */ + subdev_entity->asd = kzalloc(sizeof(*subdev_entity->asd), + GFP_KERNEL); if (!subdev_entity->asd) { of_node_put(rem); ret = -ENOMEM; @@ -2313,6 +2316,7 @@ static int atmel_isc_probe(struct platform_device *pdev) subdev_entity->asd); if (ret) { fwnode_handle_put(subdev_entity->asd->match.fwnode); + kfree(subdev_entity->asd); goto cleanup_subdev; }