Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5048636ybv; Wed, 26 Feb 2020 07:34:05 -0800 (PST) X-Google-Smtp-Source: APXvYqxwNV7J134zuO2lrvNVxeR8LmPOVo/LWWQeG+bqxtXSySuuJeC/cZGHh1TIv/Sra33hGCuD X-Received: by 2002:a05:6808:1:: with SMTP id u1mr3679197oic.74.1582731245671; Wed, 26 Feb 2020 07:34:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582731245; cv=none; d=google.com; s=arc-20160816; b=VeYmpZytCT+3GzeHmeGzkF3Uz2wmeBsugsTy95uqCpdlI/urVZqOc8GFHKAhw6TjCV YvJe01FNXzeih6x7rwsTkwo/PEkhy3tPUCjmRVUtYXrRo1OAyyNuqxbXcTHjkXtXYNnJ Kf4Dcrk2oJTp3f5InKxMU+PNUAyFRAwOsIlg7AQokx1KcHrZBs90T8q2QX0VZpks2rLS xqouVjpmksx1rJEfMknbw5DTowGYb4CwAcmrZaNqmGXTh76vPiDuQeKnBIqD7hG2oG8f BolE4xzbh7FTBWxZ+3bT4F/H/RgQlGG9udtZDZ/FBHWBoQWfICfCG9ZI0Ia+Zxcj9R20 8IHA== 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 :message-id:date:subject:cc:to:from:ironport-sdr; bh=l07KO8cEEsY4cKJ6fqDmY8GdCrvLkC8ZxIKGQu3fliM=; b=I0bPkm1QCIta1ZG8ct6WPD1tJx4I7nOQbPgznWI3+Nd8hv86/GjCeyHvN3eSpn64CS nooPZUNz9ZOWNk+iWT8SpW0ebhWx60ga4Axpck8Gaz257bGC5tf8Pp88tJZN7sgUl2jy /pEp9lwvjtNiJbOqZ6Og4QxRPgIzfzk0p/PcSmVSN8vamebnmCAGicxz9PWcZk6VSh7Z mgLyaaaZQY7CRrRCZVDLHbKkXistKkVK5qSh5PIVSmegLDhj5zwz0tztcmFWuwqGbWUa x2JY0q6i0ghUyNyI3ITy/VlhOTBxwRnHwmbeeHIwKTb1G4ghgP4Q9kz245zaf5jByMG5 hLDg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=microchip.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s128si1273617oig.204.2020.02.26.07.33.53; Wed, 26 Feb 2020 07:34:05 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728311AbgBZPcl (ORCPT + 99 others); Wed, 26 Feb 2020 10:32:41 -0500 Received: from esa3.microchip.iphmx.com ([68.232.153.233]:13958 "EHLO esa3.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728073AbgBZPck (ORCPT ); Wed, 26 Feb 2020 10:32:40 -0500 Received-SPF: Pass (esa3.microchip.iphmx.com: domain of Eugen.Hristev@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa3.microchip.iphmx.com; envelope-from="Eugen.Hristev@microchip.com"; x-sender="Eugen.Hristev@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com -exists:%{i}.spf.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa3.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa3.microchip.iphmx.com; envelope-from="Eugen.Hristev@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa3.microchip.iphmx.com; spf=Pass smtp.mailfrom=Eugen.Hristev@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: /VLtVb4iueReMInxFE5R1/eknzhBhvdoVZwpcPg2tz8kcPQ8VNEdIEQ4MJcTPOSNwCIxpQ3yMT GL92AtvPqysbGwDO4MeO70xvEjAl5j+wA1MxtYc2G7EwhMFqpXxP6E9vtODOaT250pvChjQOX0 +ezROPxuxxV77tWkMXXBsGLswax4DYnAdk90/H8KKbPCLncTAGC+ZC/WNICMFZzVNqD00cxxjc iodcSer59n0MwIJgo0xNLHifj/aMlR7o0/vaEmhXFMg3m8d42R44W9Q2SBQdIvx92Ba2EC1Ja+ vgk= X-IronPort-AV: E=Sophos;i="5.70,488,1574146800"; d="scan'208";a="68060727" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa3.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 26 Feb 2020 08:32:39 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 26 Feb 2020 08:32:51 -0700 Received: from ROB-ULT-M18282.microchip.com (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.1713.5 via Frontend Transport; Wed, 26 Feb 2020 08:32:37 -0700 From: Eugen Hristev To: , , , , CC: Eugen Hristev Subject: [PATCH v2] media: v4l2-core: fix entity initialization in device_register_subdev Date: Wed, 26 Feb 2020 17:28:16 +0200 Message-ID: <20200226152816.31557-1-eugen.hristev@microchip.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The entity variable was being initialized in the wrong place, before the parameters have been checked. To solve this, completely removed the entity variable and replaced it with the initialization value : &sd->entity. This will avoid dereferencing 'sd' pointer before it's being checked if it's NULL. Fixes: 61f5db549dde ("[media] v4l: Make v4l2_subdev inherit from media_entity") Signed-off-by: Eugen Hristev --- Changes in v2: - replaced entity with &sd->entity completely as suggested drivers/media/v4l2-core/v4l2-device.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c index 63d6b147b21e..fa9c806a8ccd 100644 --- a/drivers/media/v4l2-core/v4l2-device.c +++ b/drivers/media/v4l2-core/v4l2-device.c @@ -111,9 +111,6 @@ EXPORT_SYMBOL_GPL(v4l2_device_unregister); int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, struct v4l2_subdev *sd) { -#if defined(CONFIG_MEDIA_CONTROLLER) - struct media_entity *entity = &sd->entity; -#endif int err; /* Check for valid input */ @@ -143,7 +140,7 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, #if defined(CONFIG_MEDIA_CONTROLLER) /* Register the entity. */ if (v4l2_dev->mdev) { - err = media_device_register_entity(v4l2_dev->mdev, entity); + err = media_device_register_entity(v4l2_dev->mdev, &sd->entity); if (err < 0) goto error_module; } @@ -163,7 +160,7 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, error_unregister: #if defined(CONFIG_MEDIA_CONTROLLER) - media_device_unregister_entity(entity); + media_device_unregister_entity(&sd->entity); #endif error_module: if (!sd->owner_v4l2_dev) -- 2.20.1