Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6265613rwn; Tue, 13 Sep 2022 01:14:12 -0700 (PDT) X-Google-Smtp-Source: AA6agR6GFb5FzXV0JTWQrCu2KZDpQDL4KW1q5/76uQ3H8aFfXTJEZscN8LttC5SGf8VrSbURa/Kf X-Received: by 2002:a17:902:eb82:b0:176:c0e0:55c1 with SMTP id q2-20020a170902eb8200b00176c0e055c1mr30652443plg.168.1663056851957; Tue, 13 Sep 2022 01:14:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663056851; cv=none; d=google.com; s=arc-20160816; b=Sxlh0QJACTmE5VLQWBWH1O+55Q/voExwba7P3eWJHEv42yaMjaggAa+BKP0W50qeX9 BKKA7kGxKVUOd6EcCbFK/+f3ZRJk88KBm92u5XMdXccNW1e6SgeDE/Sgs0TBk8KHu/dh s1DpOebiyINFvQMWBl1ygztqdYM+oERIYyjQDn+WLYV5Ze+LCaq+Lzc2WMvIy3ImYy61 BX3E5pg5IMXBAIyudrh9JmylFuSQONj2ygl7Mx2XYC5gKe6mAeMXel2yrRqrDIo+t5aF G6xdaU28TbTRuyMlgIx9nmUFO0oO/rHwmnAvJe54HWJ4qUE8BB6x96xPSRztXyy09rHa wuiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=gLZ8hGiuYs/DNCzwZdjvFIM1F+jjTNT8HF27LCj8PHI=; b=iTq5HC5IyOEq54q97HeQoq7qV4ysyGsgYgvd2QwAHiZZpK6w2gqkCuibyJe2J42veQ /0sXjt/tr4e6KHjyxL6mSiKkGpE0LiqAJsePOiAb/lM/uPue7vwXb7jun29LM+andgdO rbvGgHInOE8V/JrtsYnhJLL1BcGCMsj65AIeU0l90L+DQ8NTEGZRVQrmnHPaULIYgbzS c84JwlNOetceML5+CzJCaW6BV+x7tSFabDnZAP6kgP4H2G7dPDhFeN01tah1hQwMiw7/ 5w7D6jZ97jHG83EsfN/0sy910W/Gp07slOOGyk3Jb76gh2gJOPIJhwUwvtv4Oyy15uCb mcbg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n13-20020a170902d2cd00b0017340861a6bsi11822706plc.611.2022.09.13.01.13.58; Tue, 13 Sep 2022 01:14:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230472AbiIMHb3 (ORCPT + 99 others); Tue, 13 Sep 2022 03:31:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230479AbiIMHbY (ORCPT ); Tue, 13 Sep 2022 03:31:24 -0400 Received: from cstnet.cn (smtp84.cstnet.cn [159.226.251.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2084458B5C; Tue, 13 Sep 2022 00:31:21 -0700 (PDT) Received: from localhost.localdomain (unknown [124.16.138.126]) by APP-05 (Coremail) with SMTP id zQCowACnrdXFMSBjLRMnAg--.42567S2; Tue, 13 Sep 2022 15:31:17 +0800 (CST) From: Jiasheng Jiang To: quic_jjohnson@quicinc.co, agross@kernel.org, bjorn.andersson@linaro.org, konrad.dybcio@somainline.org Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH v2] soc: qcom: apr: Add check for idr_alloc Date: Tue, 13 Sep 2022 15:31:10 +0800 Message-Id: <20220913073110.1730357-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: zQCowACnrdXFMSBjLRMnAg--.42567S2 X-Coremail-Antispam: 1UD129KBjvdXoW7Jw4rGF47XF1fur45Jw4ktFb_yoWkZFgEkF Z09ry7Xr4UCrWfG3yUJw4rZr9YkFsFqw10va1xtas3J3y5AFn7JF1DZr1fWryruw4UAw1U GF90v34xAr1F9jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbcxFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr0_ Cr1l84ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s 0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xII jxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr 1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkIecxEwVAFwVW8CwCF 04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r 18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vI r41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr 1lIxAIcVCF04k26cxKx2IYs7xG6rW3Jr0E3s1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAI cVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbhiSPUUUUU== X-Originating-IP: [124.16.138.126] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As idr_alloc() can return negative numbers, it should be better to check the return value and deal with the exception. Fixes: 6adba21eb434 ("soc: qcom: Add APR bus driver") Signed-off-by: Jiasheng Jiang --- Changelog: v1 -> v2: 1. Add dev_err and put_device in order to maintain the code consistency. --- drivers/soc/qcom/apr.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c index b4046f393575..5fef2750623a 100644 --- a/drivers/soc/qcom/apr.c +++ b/drivers/soc/qcom/apr.c @@ -454,8 +454,14 @@ static int apr_add_device(struct device *dev, struct device_node *np, adev->dev.driver = NULL; spin_lock(&apr->svcs_lock); - idr_alloc(&apr->svcs_idr, svc, svc_id, svc_id + 1, GFP_ATOMIC); + ret = idr_alloc(&apr->svcs_idr, svc, svc_id, svc_id + 1, GFP_ATOMIC); spin_unlock(&apr->svcs_lock); + if (ret < 0) { + dev_err(dev, "idr_alloc failed: %d\n", ret); + put_device(&adev->dev); + kfree(adev); + return ret; + } of_property_read_string_index(np, "qcom,protection-domain", 1, &adev->service_path); -- 2.25.1