From patchwork Tue Oct 25 15:11:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 618453 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B9D8C04A95 for ; Tue, 25 Oct 2022 15:12:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232913AbiJYPL6 (ORCPT ); Tue, 25 Oct 2022 11:11:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232633AbiJYPL6 (ORCPT ); Tue, 25 Oct 2022 11:11:58 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7E051F2C2; Tue, 25 Oct 2022 08:11:56 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id z24so7343412ljn.4; Tue, 25 Oct 2022 08:11:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=OJ2+YP+cPm60d2/5NOUBXuBeSPhDydv5METYzP/z0a4=; b=AoD0+jUlhKuShGAvHefomjU16pIUI47QirDqHeF6R9B/SKWtuWB+XEeXrH/2tq6Myx 6J90gflCVR+PUzUYY8WXi38WQ4P4vSseIBqz6UL3LKdbHtnaI5Sn4ECWDpp+SgBYd3Cw HL4xWKl3CC+KX2lTfwpL3OwnJgamLbFIF5zxasQFa/AJLcawT2MffG2+1MOIwhJUXO5B 1TAIcN8YJTrFEmWliIeSsNorOv9OvOo8zTycao/B9KOxF47lC2tv5s6lpqdG0IIECG+x XH6P+0XpejVLFiJ7AKJYf3S8SkJv+c/q5bZ9YPYHdpidp5bf+J4y2Ry1a2Oidtzr+31/ 9olg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=OJ2+YP+cPm60d2/5NOUBXuBeSPhDydv5METYzP/z0a4=; b=hUgWAHN9m0QooupihleE9tTHAWO5L66beu9V+QOtNyQMHX6uVLcKJ5poqE0kYqHhCL /zYEVYnfouxGS76kzVKBquDgC/Z/1SfY0tzymvZa5I+OJRNyhHBeLmi7zHYBrFeDiE+F VdjSTSysK+//8yyT+tqZpiL5Kk27oh8p3MJ2g8YoTDhEaXiEqDW4YUktMzLrW6jKEQFu lWJrJhYiznPN6XAlpsovMNDzbjB7BtHIOwNjDBD7dFMnkR1gOIiUs+8/JtiEIi0bwDRn Pq605RTspktS61huij1TBwKB22m1jSr2YUpl0DzMquxyP8R1XCJZC5Ly84ArnGZmJZLg eE+w== X-Gm-Message-State: ACrzQf1Ic5U2WpoSv8LngjK7Ni9LykTennuSmD81vhAj7SnP6sat/wFi y9bIm7SPZzuyB2E8zhzG9gs= X-Google-Smtp-Source: AMsMyM4RpDJZQC14HbxKi/x9pYMmm2HRPKLbHmzUIaGRcuIwg5PACYftISFclsh6Z1EYORgJJYz6BA== X-Received: by 2002:a05:651c:1111:b0:26f:eb56:5844 with SMTP id e17-20020a05651c111100b0026feb565844mr15107789ljo.4.1666710715209; Tue, 25 Oct 2022 08:11:55 -0700 (PDT) Received: from dc75zzyyyyyyyyyyyyyby-3.rev.dnainternet.fi (dc75zzyyyyyyyyyyyyyby-3.rev.dnainternet.fi. [2001:14ba:16f3:4a00::2]) by smtp.gmail.com with ESMTPSA id c7-20020a056512074700b004a46f92a15bsm455046lfs.41.2022.10.25.08.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 08:11:54 -0700 (PDT) Date: Tue, 25 Oct 2022 18:11:49 +0300 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J. Wysocki" , Wolfram Sang , Akhil R , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org Subject: [PATCH v2 1/2] drivers: fwnode: fix fwnode_irq_get_byname() Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The fwnode_irq_get_byname() does return 0 upon device-tree IRQ mapping failure. This is contradicting the function documentation and can potentially be a source of errors like: int probe(...) { ... irq = fwnode_irq_get_byname(); if (irq <= 0) return irq; ... } Here we do correctly check the return value from fwnode_irq_get_byname() but the driver probe will now return success. (There was already one such user in-tree). Change the fwnode_irq_get_byname() to work as documented and according to the common convention and abd always return a negative errno upon failure. Fixes: ca0acb511c21 ("device property: Add fwnode_irq_get_byname") Suggested-by: Sakari Ailus Signed-off-by: Matti Vaittinen Reviewed-by: Sakari Ailus Reviewed-by: Andy Shevchenko --- v1 => v2: - change check if (!ret) => if (ret == 0), add comment. - fix drop redundant empty line. I did a quick audit for the callers at v6.1-rc2: drivers/i2c/i2c-smbus.c drivers/iio/accel/adxl355_core.c drivers/iio/gyro/fxas21002c_core.c drivers/iio/imu/adis16480.c drivers/iio/imu/bmi160/bmi160_core.c drivers/iio/imu/bmi160/bmi160_core.c I did not spot any errors to be caused by this change. There will be a functional change in i2c-smbus.c as the probe will now return -EINVAL should the IRQ dt-mapping fail. It'd be nice if this was checked to be Ok by the peeps knowing the i2c-smbus :) --- drivers/base/property.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index 4d6278a84868..b4ccc64f7bd2 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -964,7 +964,7 @@ EXPORT_SYMBOL(fwnode_irq_get); */ int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name) { - int index; + int index, ret; if (!name) return -EINVAL; @@ -973,7 +973,12 @@ int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name) if (index < 0) return index; - return fwnode_irq_get(fwnode, index); + ret = fwnode_irq_get(fwnode, index); + /* We treat mapping errors as invalid case */ + if (ret == 0) + return -EINVAL; + + return ret; } EXPORT_SYMBOL(fwnode_irq_get_byname); From patchwork Tue Oct 25 15:12:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 619037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79BE5ECDFA1 for ; Tue, 25 Oct 2022 15:12:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232480AbiJYPMW (ORCPT ); Tue, 25 Oct 2022 11:12:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232946AbiJYPMU (ORCPT ); Tue, 25 Oct 2022 11:12:20 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10A9740BD9; Tue, 25 Oct 2022 08:12:19 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id u2so8169642ljl.3; Tue, 25 Oct 2022 08:12:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=i3VCaLUSkP0MHn9g1Bdf8SvWr5beC5vVRYzG/hEHOwM=; b=KTXHatYhfbJ2a1sMmM8whproz8b9Ke5Q7Nnzl12OSpOZiXx2lNMEkbn0qSlv0WvCbd 7T0E/h+cX2gK+AVbtSMBG/I1CuRTDL1tMME+E5KkPVn+oghs3XSqj+RKpjkBSBxQZbMW 94mZIyqeZRnuHH/3uSzyyGuEVGrL77eXiScoBqnSO978mmuxRreEpOIEqnoFXqaCrYxy g5VQLqd6SQoo6P48TPIWMstK2atLw0NASknSIC7DdswGQuZATKNYy7sdqSDg02C+/ZTB KnEmC+dkqLARf7ALRt2jx96PYE9aqWBguXjkGmu19mONskqZDIfC3CcnmI+/PoDOtgdY kMog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=i3VCaLUSkP0MHn9g1Bdf8SvWr5beC5vVRYzG/hEHOwM=; b=4g4Y4vgumlDH7SvqBzY64abRzb1C16FTjwCbDLxMe5Cu1o9qmQmfy8tGnVPnENzMRi ogrXUve8ClgJ667S+m6nPTEZy71WbosCBIwZplsY9lQ3Owvp/b14DgdiIm3kBOL5/L1g 4iptTQ6rXTVCsyRLlHOlviuQKuaf2rC7s5QEIH5qp9pKlot/Sg7WC+TdzHGinu4Y13aa SaC+IiUXup4G3eR+ateH61nX4BzkfrjGl0ZT0UXrjwXrY356Wr0m2b59eKtIXtpMlGw8 CPKM8MvTzv9JiM/hNrey276DdCDGf1LMzxct4xEu+yqi68X5BxvgJ0XNPG+gj7EY+8W5 ZpBg== X-Gm-Message-State: ACrzQf0ChNU/aeXdPwvb2zTdsHfQEjeLMEPdeq3yj5vLy+1o2xR8LBvf NXQ5siF4r5EnFDbWH3g5pnA= X-Google-Smtp-Source: AMsMyM4jlDjlJdOcztU47g3WlSh0KAN2tsPbAB0uuR9Wdc6tOFQwxyKUmQJCshu5WmoQd2gwwryK1A== X-Received: by 2002:a05:651c:1241:b0:261:9313:9cb9 with SMTP id h1-20020a05651c124100b0026193139cb9mr14393521ljh.213.1666710737399; Tue, 25 Oct 2022 08:12:17 -0700 (PDT) Received: from dc75zzyyyyyyyyyyyyyby-3.rev.dnainternet.fi (dc75zzyyyyyyyyyyyyyby-3.rev.dnainternet.fi. [2001:14ba:16f3:4a00::2]) by smtp.gmail.com with ESMTPSA id r7-20020a2eb607000000b0026befa96249sm545053ljn.8.2022.10.25.08.12.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 08:12:16 -0700 (PDT) Date: Tue, 25 Oct 2022 18:12:11 +0300 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J. Wysocki" , Wolfram Sang , Akhil R , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org Subject: [PATCH v2 2/2] i2c: i2c-smbus: fwnode_irq_get_byname() return value fix Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The fwnode_irq_get_byname() was changed to not return 0 upon failure so return value check can be adjusted to reflect the change. Signed-off-by: Matti Vaittinen Reviewed-by: Sakari Ailus Reviewed-by: Andy Shevchenko --- Depends on the mentioned return value change which is in patch 1/2. The return value change does also cause a functional change here. Eg. when IRQ mapping fails, the fwnode_irq_get_byname() no longer returns zero. This will cause also the probe here to return nonzero failure. I guess this is desired behaviour. --- drivers/i2c/i2c-smbus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c index 07c92c8495a3..d0cc4b7903ed 100644 --- a/drivers/i2c/i2c-smbus.c +++ b/drivers/i2c/i2c-smbus.c @@ -130,7 +130,7 @@ static int smbalert_probe(struct i2c_client *ara, } else { irq = fwnode_irq_get_byname(dev_fwnode(adapter->dev.parent), "smbus_alert"); - if (irq <= 0) + if (irq < 0) return irq; }