From patchwork Fri May 4 13:56:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tenart X-Patchwork-Id: 10380685 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B335660353 for ; Fri, 4 May 2018 14:11:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91E0A29479 for ; Fri, 4 May 2018 14:11:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85FC92947D; Fri, 4 May 2018 14:11:22 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6240A29479 for ; Fri, 4 May 2018 14:11:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=gQ6iJmjC6X7m6tzqq9pOnz2sOm9MG8t/GV5RFuRmAnw=; b=jJix86vkFPwYdUWkX1Ljvag6/1 T8gVruYi/rHeR2lyCcHdXZedX46XpUvvJI6dtxrKbJnw1VQux26ejsIGEKNKgmZHIkjNMEEc1H1j7 D3jENeKzeLGMljjRZ1rLht/LujnxIblay09FCXToclo/vUL8tS1wnYJuYvxy30GMriLB1Ja2HdLen sx0Xkix7lUnsSR2pNQRFJr2TOn7DhDV+SU5TiQGCXKCR5dFIZ8WQuWJxmcvvIhqfCdvmfR+m2UE39 8zfo8Iq5l6S0Vk4d2x8VjH1Ijk0bNYFG5x7hwmew7V0HZ0mHsYpP7AqYce7Tw0rEiDOCYddbxLKmT +A7PYn2g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fEbQW-0002ea-D5; Fri, 04 May 2018 14:11:12 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fEbPj-0000bU-Oj for linux-arm-kernel@bombadil.infradead.org; Fri, 04 May 2018 14:10:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=NO/vm1eu8hpUpFxMW0HGk4EEDbkveODeweEdU3D4ZIc=; b=NK9AvNnbuR9sh8E5kUn89Kphn LfmjcO3zYQik5C3PObZrY/R2+GconTNlqQG9yKw8oehkEVAq4r0INumVdEn6e9cJaXOSxkYNedws3 KzM0Wtd69jLkSet6803SkAc9AVKFm8z1hYj9DB6IF/YKvu5Zwf8gKSEPCzjuTUaM6AliaG/7WjY/Q Vu3q98oAY1iO3NFTyM+G8mByTN/krdHfUMqYzp1ib0SZ5AZbTzpT7jzcOeyze8RsdeM+rpHOIxtj7 zgkFNnDq4JY4T1stAyHJB9DoufB864Pf8e0l5CR/r1CyiH3sCyv7loiwVyWKx4HSE2K8lOE1vsiq6 BTpQJ9lYQ==; Received: from mail.bootlin.com ([62.4.15.54]) by casper.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fEbGG-0005Bk-Q8 for linux-arm-kernel@lists.infradead.org; Fri, 04 May 2018 14:00:39 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id 28E7820829; Fri, 4 May 2018 16:00:13 +0200 (CEST) Received: from localhost (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.bootlin.com (Postfix) with ESMTPSA id ED2772082C; Fri, 4 May 2018 16:00:02 +0200 (CEST) From: Antoine Tenart To: davem@davemloft.net, kishon@ti.com, linux@armlinux.org.uk, gregory.clement@bootlin.com, andrew@lunn.ch, jason@lakedaemon.net, sebastian.hesselbarth@gmail.com Subject: [PATCH net-next v2 01/13] net: phy: sfp: make the i2c-bus property really optional Date: Fri, 4 May 2018 15:56:31 +0200 Message-Id: <20180504135643.23466-2-antoine.tenart@bootlin.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180504135643.23466-1-antoine.tenart@bootlin.com> References: <20180504135643.23466-1-antoine.tenart@bootlin.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180504_150036_913913_02A1930C X-CRM114-Status: GOOD ( 13.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ymarkman@marvell.com, Antoine Tenart , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, maxime.chevallier@bootlin.com, nadavh@marvell.com, thomas.petazzoni@bootlin.com, miquel.raynal@bootlin.com, stefanc@marvell.com, mw@semihalf.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The SFF,SFP documentation is clear about making all the DT properties, with the exception of the compatible, optional. In practice this is not the case and without an i2c-bus property provided the SFP code will throw NULL pointer exceptions. This patch is an attempt to fix this. Signed-off-by: Antoine Tenart --- drivers/net/phy/sfp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index 4ab6e9a50bbe..4686c443fc22 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c @@ -298,11 +298,17 @@ static void sfp_set_state(struct sfp *sfp, unsigned int state) static int sfp_read(struct sfp *sfp, bool a2, u8 addr, void *buf, size_t len) { + if (!sfp->read) + return -EOPNOTSUPP; + return sfp->read(sfp, a2, addr, buf, len); } static int sfp_write(struct sfp *sfp, bool a2, u8 addr, void *buf, size_t len) { + if (!sfp->write) + return -EOPNOTSUPP; + return sfp->write(sfp, a2, addr, buf, len); } @@ -533,6 +539,8 @@ static int sfp_sm_mod_hpower(struct sfp *sfp) return 0; err = sfp_read(sfp, true, SFP_EXT_STATUS, &val, sizeof(val)); + if (err == -EOPNOTSUPP) + goto err; if (err != sizeof(val)) { dev_err(sfp->dev, "Failed to read EEPROM: %d\n", err); err = -EAGAIN; @@ -542,6 +550,8 @@ static int sfp_sm_mod_hpower(struct sfp *sfp) val |= BIT(0); err = sfp_write(sfp, true, SFP_EXT_STATUS, &val, sizeof(val)); + if (err == -EOPNOTSUPP) + goto err; if (err != sizeof(val)) { dev_err(sfp->dev, "Failed to write EEPROM: %d\n", err); err = -EAGAIN; @@ -565,6 +575,8 @@ static int sfp_sm_mod_probe(struct sfp *sfp) int ret; ret = sfp_read(sfp, false, 0, &id, sizeof(id)); + if (ret == -EOPNOTSUPP) + return ret; if (ret < 0) { dev_err(sfp->dev, "failed to read EEPROM: %d\n", ret); return -EAGAIN;