From patchwork Wed Nov 21 10:59:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rui Miguel Silva X-Patchwork-Id: 10692381 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 0BB7E1869 for ; Wed, 21 Nov 2018 11:00:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEC802B809 for ; Wed, 21 Nov 2018 11:00:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E313E2B826; Wed, 21 Nov 2018 11:00:31 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 845362B809 for ; Wed, 21 Nov 2018 11:00:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729353AbeKUVe0 (ORCPT ); Wed, 21 Nov 2018 16:34:26 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:34665 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726172AbeKUVeZ (ORCPT ); Wed, 21 Nov 2018 16:34:25 -0500 Received: by mail-wr1-f67.google.com with SMTP id j2so5206921wrw.1 for ; Wed, 21 Nov 2018 03:00:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PXCGK9Ve8iSu7XzE/ltFaekKuCzhH8LEUlwpQxSrky4=; b=BPrxSlkd+Kh9mBa2F0NaEv/ZANFF3MHOu5kwKUabTug8o7gkoYE7VyNx0L09VA6NwG RDOVxSMQPJCtFQaTe9croNk3mVaEfOXMSR8hQc38EKOVcU/M+e0pULqX1fbo4MWUYwZQ fZkMEwXhuQZ8xtg7a8SN0T9so3Y8CcpSv6ARQ= 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:mime-version :content-transfer-encoding; bh=PXCGK9Ve8iSu7XzE/ltFaekKuCzhH8LEUlwpQxSrky4=; b=C61oKA5c22sV/qlPwWGK1NYYgzaFK7qODnyinbipJt+4llm7krXjEocdWMq7SnQDOX Kk54ta/Vq8uMMoPpX6319l9FShFgAT7Rb6cRis8qbGNyzTLiYWF7aOp8xSI6Tpr4IuIE evla19EJ/QQdAqNLW4UkztpFgfbF98bjZ1A9aiMCKc0SAG1mHAR2C1kFm5rlgp1ZH3b2 0WoORx8DgaKZuSuiZUaGIJOpyNCcsqREinEFmt1et3/4njLnYj/MWRcbYQivW8yQ19O9 Q68Vbxvl5Wmk/HBMX0+bun3906mUkyqIbvN40JFJ1A0rWeBbEBEqjTsHKZdWzpjNFS3a LFaA== X-Gm-Message-State: AA+aEWYZoNvQQoU67CuTF5nIIKBeHZ+twYNsuftibV+TW+uYw6oe8Pp/ Iiis4lw8EeBRjJxeTCHQZAPwQw== X-Google-Smtp-Source: AFSGD/Vmdo7c2IZ3XXt0IpvVakvf2DHhe1lBLvHrqBoL902nWDtcHqWBJD5VsQhj8D3Tz5+WTI9STg== X-Received: by 2002:adf:e64d:: with SMTP id b13mr5453821wrn.276.1542798028491; Wed, 21 Nov 2018 03:00:28 -0800 (PST) Received: from arch-late.local (a109-49-46-234.cpe.netcabo.pt. [109.49.46.234]) by smtp.gmail.com with ESMTPSA id 3-v6sm27493662wrs.44.2018.11.21.03.00.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Nov 2018 03:00:28 -0800 (PST) From: Rui Miguel Silva To: sakari.ailus@linux.intel.com Cc: linux-media@vger.kernel.org, Javier Martinez Canillas , Rui Miguel Silva Subject: [PATCH] media: ov2680: fix null dereference at power on Date: Wed, 21 Nov 2018 10:59:55 +0000 Message-Id: <20181121105955.9217-1-rui.silva@linaro.org> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 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 Swapping the order between v4l2 subdevice registration and checking chip id in b7a417628abf ("media: ov2680: don't register the v4l2 subdevice before checking chip ID") makes the mode restore to use the sensor controls before they are set, so move the mode restore call to s_power after the handler setup for controls is done. This remove also the need for the error code path in power on function. Fixes: b7a417628abf ("media: ov2680: don't register the v4l2 subdevice before checking chip ID") Signed-off-by: Rui Miguel Silva --- drivers/media/i2c/ov2680.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index 0e34e15b67b3..b10bcfabaeeb 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -568,10 +568,6 @@ static int ov2680_power_on(struct ov2680_dev *sensor) if (ret < 0) return ret; - ret = ov2680_mode_restore(sensor); - if (ret < 0) - goto disable; - sensor->is_enabled = true; /* Set clock lane into LP-11 state */ @@ -580,12 +576,6 @@ static int ov2680_power_on(struct ov2680_dev *sensor) ov2680_stream_disable(sensor); return 0; - -disable: - dev_err(dev, "failed to enable sensor: %d\n", ret); - ov2680_power_off(sensor); - - return ret; } static int ov2680_s_power(struct v4l2_subdev *sd, int on) @@ -606,6 +596,8 @@ static int ov2680_s_power(struct v4l2_subdev *sd, int on) ret = v4l2_ctrl_handler_setup(&sensor->ctrls.handler); if (ret < 0) return ret; + + ret = ov2680_mode_restore(sensor); } return ret;