From patchwork Sat Sep 1 12:46:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Martinez Canillas X-Patchwork-Id: 51838 X-Patchwork-Delegate: sakari.ailus@iki.fi Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fw5IV-0005ly-M2; Sat, 01 Sep 2018 12:46:39 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727528AbeIAQ6e (ORCPT + 1 other); Sat, 1 Sep 2018 12:58:34 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:51439 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726837AbeIAQ6e (ORCPT ); Sat, 1 Sep 2018 12:58:34 -0400 Received: by mail-wm0-f66.google.com with SMTP id y2-v6so7503376wma.1 for ; Sat, 01 Sep 2018 05:46:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=+e7PacGEQJyefIybs72FItPu9MA3wQVdBoFJ1XZSXrw=; b=TyVGoCvYmOBQ2BY78VdrmsAeQ3wm9YnGZvcT2Ankhh9Sk49cEnWIp4/nhTn2cEBEtx s7qRfpvjDAIoHG5aSdZjtLKdFXPibTxoRvWKdZHoE5IwpTYwj+uy13MtWxUPuCWlzQEl D172dZZ8JSyO/zD1pDvu+oo4Esv3qDCcTi0xmQAORD+DS4dS8a6h8u6N7FQcZWq7CN/V GmL9/5J0TXmXwQ3JKyIidt8zlBTQbgUfFJhlb2RmzmSrMdPQ4mZQN2iV8/pX2B/FnwZh qkCK5Z0L97U5DEuHb9MUYehW48qAOIWtogbrN94upSkn3RNyounRcJp0HCU8W5F1x5lv MkQA== X-Gm-Message-State: APzg51CrQcEm84Ltbq0wMktfuTDyA6Vj1LxcfR6iIiufQ127tsEwNfrG ikE6lIuSnT5DYKxrfpBn8m+glA== X-Google-Smtp-Source: ANB0VdZ0lLlB54ENGLHuvzrUdHg/wohlwyZKdJslqNwMpv5DSkO9WQsidDlrjFHVim8a3WUsTBqRwA== X-Received: by 2002:a1c:230f:: with SMTP id j15-v6mr696485wmj.124.1535805996523; Sat, 01 Sep 2018 05:46:36 -0700 (PDT) Received: from minerva.home ([90.168.169.92]) by smtp.gmail.com with ESMTPSA id q3-v6sm8515547wma.45.2018.09.01.05.46.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 01 Sep 2018 05:46:35 -0700 (PDT) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: Sakari Ailus , Javier Martinez Canillas , Mauro Carvalho Chehab , Rui Miguel Silva , linux-media@vger.kernel.org Subject: [PATCH v2 1/2] media: ov2680: don't register the v4l2 subdevice before checking chip ID Date: Sat, 1 Sep 2018 14:46:29 +0200 Message-Id: <20180901124630.14139-1-javierm@redhat.com> X-Mailer: git-send-email 2.17.1 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The driver registers the v4l2 subdevice before attempting to power on the chip and checking its ID. This means that a media device driver that it's waiting for this subdevice to be bound, will prematurely expose its media device node to userspace because if something goes wrong the media entity will be cleaned up again on the ov2680 probe function. This also simplifies the probe function error path since no initialization is made before attempting to enable the resources or checking the chip ID. Fixes: 3ee47cad3e69 ("media: ov2680: Add Omnivision OV2680 sensor driver") Signed-off-by: Javier Martinez Canillas --- Changes in v2: - Just move ov2680_check_id() before ov2680_v4l2_init() - Suggested by Sakari. drivers/media/i2c/ov2680.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index f753a1c333ef..3ccd584568fb 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -1088,26 +1088,20 @@ static int ov2680_probe(struct i2c_client *client) mutex_init(&sensor->lock); - ret = ov2680_v4l2_init(sensor); + ret = ov2680_check_id(sensor); if (ret < 0) goto lock_destroy; - ret = ov2680_check_id(sensor); + ret = ov2680_v4l2_init(sensor); if (ret < 0) - goto error_cleanup; + goto lock_destroy; dev_info(dev, "ov2680 init correctly\n"); return 0; -error_cleanup: - dev_err(dev, "ov2680 init fail: %d\n", ret); - - media_entity_cleanup(&sensor->sd.entity); - v4l2_async_unregister_subdev(&sensor->sd); - v4l2_ctrl_handler_free(&sensor->ctrls.handler); - lock_destroy: + dev_err(dev, "ov2680 init fail: %d\n", ret); mutex_destroy(&sensor->lock); return ret;