From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E82BF320A0B for ; Wed, 1 Apr 2026 18:17:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775067427; cv=none; b=AvkBYyl1mro19ouZXtB7dZps+6moYul5M3UWtYS+n9hiiEacrL3JObJEZroF0pGsUI17GBsGRtwTdIyh9OBIqUcRrPZd+uEWpY76NuHBlh71cj1I1UpN0FB/DvW7MFsucNvDacnzRcU1Dhg0LU/4wIx6wAi4e+MxJLj0+E70TA0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775067427; c=relaxed/simple; bh=IX+wQq4T5DKVzSw6Vp9g1t+wnTvP/wCU3zamd2onuXY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=oS91fT+pGBQdj13P7CydMHtIVabSGu3O+SeD7OX4QY4nXQIHwS0Jsv5W9QkaTzNS+Tzm1t0zaIeoTnTBQg9P9lFUJ+gxLXERF6Tzs4vIogHRScVmnRSTBT3s/M1oFpNr/U72kKxs4yADEI3iKlD1GD9x4oFlF8QLZBuNyhfuf0g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UQlFlopo; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UQlFlopo" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-82cf976ecacso26299b3a.1 for ; Wed, 01 Apr 2026 11:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775067425; x=1775672225; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=21SX5y/GcmnmuEOgAc+fgSaPS9NksSYjs5veJdbCAfg=; b=UQlFlopoYf9iq6JOJmdq3vSKShpgIsWgWAx8ZCN9Jc64x0pH+XWyx3vgr5mCbk8dG+ FQV41iaVh7sbbEpGCvtgnLn9GdLS5YbZsGQPH/oJyVdyEkVI7fqmSpJhjHvVk9EFdbPF 3/atNzhM/SsYQWYZgcTfd/Z8vUQbYqWjp2fHvv+IvbMF5chK3SagTwZGbWGS+aS0zMNv xKsd5CediUKkd9QjyZhdxpFnpYYf8AYhARuQLf4K60asj91wN3/0ug/jkoqtG3wxv1/i EV+ctMLfyGJ0Fn+sNW0QNvS56P2shSSkrFAEomXa4Cal7IRY0jBSVI65+3irAIE5DLXP s5kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775067425; x=1775672225; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=21SX5y/GcmnmuEOgAc+fgSaPS9NksSYjs5veJdbCAfg=; b=C6KVNALD/YqkV/PNHaCdMFJUCB3AWfXbb9Ogcd4xUK8FX+X84W9cM5zY57q+cTsj/2 D+9wKYY/gRBqB1kiJq3CJYZbOFYKa+IRwvz5QBH4JisVe5QMAQrhnkY35hrCbCckQW2x j5hZ3sElw/ufuQszW+Yqj4YOwYvD4MqD/1EBz6yF4DqFGWCSFjaI9khD9remQPZZSqf+ wFGn+C+nEIq39ANVqNbDzHRPtsjP9VHo1szctlEs9I61RsPokVp+GZeItehwP3GMklFY ea/dECC9JOXu8Wa83KZI1eWXbd4V3DdS0/alf8v2qUUbY1Iyl3K4oPPPAnW/fmWHXZ1J 4Y8w== X-Forwarded-Encrypted: i=1; AJvYcCWPHSQTNdY/J9UrzYtC4nBS2nvWTRJeUhcw2j5Pm27SXqZoLmtzSG3axSM1VswtV0EPXiw5THvpCYsh4Mk=@vger.kernel.org X-Gm-Message-State: AOJu0YxZdbpCATcLGD342f4FMttkqt1vYHbo8Cq/0oaM8SqV/m9wX/ul sOT/KjKHPWjyNStqWxMiBVqoQNXwz0dasoFVnCMwMT3nUZ4JwrEx/O/O X-Gm-Gg: ATEYQzyjzAry652KdDRVd/NxnWKlW9MKhYky+XEY1JI4Dk3jimrYTEle/o55PoCmMbe +CgstFngSUehXGLlqnWyufjq1HL4Ui5vqmEoCxfMp81dyjiJigHWj+2itdbnOAWHSTGohMkRIb0 z8h37yeXhzigIMOfcIwbcC2B8Mg58uORd5UtQXtFf+H0GZXZdy4zAOftQJg/5cNd/unfwh/KASz 2++XMt1KB+6hxeh4j0U1J5b+MD588F6NYo9Ic7SY8TrHA1lh0YI08UW9bTOiaEBjw4rk3ZXbUGz UBxEQifPW/hL4CP8VnogOtvMaEV15yuTFtXXsj3m9vGuvDloHweXZoy/jP16bzDEtsW3RybucQZ ZGA+NUIEK8hT0yldlocOdPWDuqi4JjEUeJBNXBTpx2hhqEPiZV4oiVUjAyHAB2a2JTyaOj6Ll2R Mj0dfFdlHoKsCeXGS2gc2wOvGFqvydOsq2ERO1I1PTGewHbVN7 X-Received: by 2002:a05:6a00:a0f:b0:829:8041:83f with SMTP id d2e1a72fcca58-82ce88d4c86mr4873022b3a.7.1775067425265; Wed, 01 Apr 2026 11:17:05 -0700 (PDT) Received: from hu-ckantibh-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82cf9ca14b3sm666249b3a.54.2026.04.01.11.17.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2026 11:17:04 -0700 (PDT) From: Sanjay Chitroda X-Google-Original-From: Sanjay Chitroda To: hansg@kernel.org, sakari.ailus@linux.intel.com, mchehab@kernel.org Cc: hverkuil+cisco@kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] media: i2c: gc0310: fix probe error handling and unwind resources properly Date: Wed, 1 Apr 2026 23:46:55 +0530 Message-Id: <20260401181657.654055-2-sanjayembedded@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260401181657.654055-1-sanjayembedded@gmail.com> References: <20260401181657.654055-1-sanjayembedded@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Sanjay Chitroda The GC0310 probe path currently performs error cleanup by jumping to a common label that mirrors the driver's remove() callback. This is unsafe, as remove() assumes that the subdevice has been fully registered with the V4L2 framework, media and control resources have been initialized. Calling remove() from probe can result in unregistering or cleaning up subdevice, leading to resource leaks and subtle lifecycle bugs. Rewrite the probe() error handling to unwind resources explicitly, using fine‑grained goto labels along with appropriate error logs. Each failure path now frees only successfully acquired resource, without remove(). This aligns the driver with standard V4L2 sensor lifecycle expectations and avoids incorrect teardown during probe failures. Fixes: 1e72afb5146a ("media: Move gc0310 sensor drivers to drivers/media/i2c/") Signed-off-by: Sanjay Chitroda --- drivers/media/i2c/gc0310.c | 39 ++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/drivers/media/i2c/gc0310.c b/drivers/media/i2c/gc0310.c index 7af4d66f42a0..72a82ad4118a 100644 --- a/drivers/media/i2c/gc0310.c +++ b/drivers/media/i2c/gc0310.c @@ -721,7 +721,7 @@ static int gc0310_probe(struct i2c_client *client) ret = gc0310_detect(sensor); if (ret) - goto err_power_down; + goto error_power_off; sensor->sd.internal_ops = &gc0310_internal_ops; sensor->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; @@ -730,20 +730,27 @@ static int gc0310_probe(struct i2c_client *client) ret = gc0310_init_controls(sensor); if (ret) - goto err_power_down; + goto error_power_off; ret = media_entity_pads_init(&sensor->sd.entity, 1, &sensor->pad); - if (ret) - goto err_power_down; + if (ret) { + dev_err_probe(&client->dev, ret, "failed to init entity pads\n"); + goto error_handler_free; + } sensor->sd.state_lock = sensor->ctrls.handler.lock; ret = v4l2_subdev_init_finalize(&sensor->sd); - if (ret) - goto err_power_down; + if (ret) { + dev_err_probe(&client->dev, ret, "subdev init error\n"); + goto error_media_entity; + } ret = v4l2_async_register_subdev_sensor(&sensor->sd); - if (ret) - goto err_power_down; + if (ret) { + dev_err_probe(&client->dev, ret, + "failed to register gc0310 sub-device\n"); + goto error_subdev_cleanup; + } pm_runtime_set_autosuspend_delay(&client->dev, 1000); pm_runtime_use_autosuspend(&client->dev); @@ -751,9 +758,21 @@ static int gc0310_probe(struct i2c_client *client) return 0; -err_power_down: +error_subdev_cleanup: + v4l2_subdev_cleanup(&sensor->sd); + pm_runtime_disable(&client->dev); + pm_runtime_set_suspended(&client->dev); + +error_media_entity: + media_entity_cleanup(&sensor->sd.entity); + +error_handler_free: + v4l2_ctrl_handler_free(&sensor->ctrls.handler); + +error_power_off: pm_runtime_put_noidle(&client->dev); - gc0310_remove(client); + gc0310_power_off(&client->dev); + return ret; } -- 2.34.1