From patchwork Tue Jun 25 06:41:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacky Huang X-Patchwork-Id: 13710687 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 946C0C2BBCA for ; Tue, 25 Jun 2024 06:41:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=FiSYpkCCJa2ynYPvssadIcTJSgGBXf+md4v4r1uNPxk=; b=ljppUfPirCBDfZiAdifENkDBFZ KYW9Opl3yKRYC/z9cP0hJ9yl9y6YGxusxu+/WfSq7HA6ve6DBF/zNQpsTunFnFrtbuj/WP0QgnLc2 PHEkYaE0SinR+42RluZVYqnCcXOmQLaRWqoCbJNxO9gX/MTwKxAnHw2LVSfUwa8y4kST8zL1gU8qa gh/7YHXk0jI7r9wcdEvt4gAd32+3Yu8EUzR6FMG0+YBNve4eRKWe0Nv9ktZQjbrfDOodKHu6Ds0ZZ y6qfeolzsrH+uAkU5noYB1Va4kQatL1UjdQ0tRrSZty7h2Fq4tYFS6HctyqdqlrkODb8VgdOCjRa4 pfpc06qA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLzs4-00000001pS3-01DW; Tue, 25 Jun 2024 06:41:40 +0000 Received: from mail-oo1-xc2d.google.com ([2607:f8b0:4864:20::c2d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLzry-00000001pR6-3cF5 for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 06:41:36 +0000 Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-5baf982f56dso2576674eaf.3 for ; Mon, 24 Jun 2024 23:41:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719297694; x=1719902494; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=FiSYpkCCJa2ynYPvssadIcTJSgGBXf+md4v4r1uNPxk=; b=g5Y6as/nxE9a5P+ea4lQXazQ+5JvsEfmhq5b+hqWopkP68yJWX7LDugdFD6MH5netl Z5W3Wlwsvz+0IPcsYioh4EX4XuYoAQD6xhSMIPDLgxNsby2HKxC2y7IxM8F/pIO3Xuwy CjLCsPfE5jXjCinUpglgTPATzZcDj+fqM/TK/M5panqCVxOoiE+OsC6kpdUVWOD8pLPp E3xmsh/4V9B3bSxruCZGdF8jdNVVZSYW70GKq7Jcp+8+lP8djItUaRk1CICjhGT7AknI KzDa4Q4V3sP3V458Kj5w9ozACTRkhZpEWyqgWiC4Q0UY231mYtp4RyUyRt3Z9/YNCC3M GP3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719297694; x=1719902494; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FiSYpkCCJa2ynYPvssadIcTJSgGBXf+md4v4r1uNPxk=; b=JgOjlWrqpJDx0FHxQUdKqwl43h2QxpiJ+f/318bUFI5QZjyamfJcK9x1PixG9GQesE x+YgaBbjsZ4X42uEu4sz+BEuJJSGdZUM1mWQU1e62m3Bjw10SPSZhb5lliEnG/v1rZHb VCV8Te/urILyzO1AZDsgRCZ7s+7Fpk4gh9NRk13GfG1n/r1KSWlxco4gwgBEWIJ3bSr3 Hqo8BvYds++95/mvlJgDUjldvToCeY15+6kkiIkSKvT6tt/AaPpCJ/I1iYhxeEg83ItQ msJyYucp31vMIyL7b5zRXHoGPv+TY1MaoJlGKlNh4OhVglzRevYMo2qty1+YE47ITc40 EiiQ== X-Gm-Message-State: AOJu0YycjItgE4z2XNbS6ENihcNlVOzD8YnrlFGc04g33+y9tlMPtNnl r5Aww9IIPmXgNma0Y5in3knGuTmwlRPDdG6X1Xb3nYxLsiV8YqUb X-Google-Smtp-Source: AGHT+IGmIpEK4h/noSZzXdtXPUoa2gfvobkZ9aziSZjqfvV0nYXycfKGs8LIX1ntFV+Jz3PSf+QVjw== X-Received: by 2002:a05:6870:1654:b0:254:affe:5a05 with SMTP id 586e51a60fabf-25d06c1c1ddmr6826956fac.21.1719297693828; Mon, 24 Jun 2024 23:41:33 -0700 (PDT) Received: from a28aa0606c51.. (60-250-192-107.hinet-ip.hinet.net. [60.250.192.107]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706512e64afsm7317879b3a.189.2024.06.24.23.41.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 23:41:33 -0700 (PDT) From: Jacky Huang To: dan.carpenter@linaro.org, gregkh@linuxfoundation.org, jirislaby@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Jacky Huang Subject: [PATCH v4] tty: serial: ma35d1: Add a NULL check for of_node Date: Tue, 25 Jun 2024 06:41:28 +0000 Message-Id: <20240625064128.127-1-ychuang570808@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240624_234134_947590_F358DBA0 X-CRM114-Status: GOOD ( 14.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jacky Huang The pdev->dev.of_node can be NULL if the "serial" node is absent. Add a NULL check to return an error in such cases. Fixes: 930cbf92db01 ("tty: serial: Add Nuvoton ma35d1 serial driver support") Reported-by: Dan Carpenter Closes: https://lore.kernel.org/all/8df7ce45-fd58-4235-88f7-43fe7cd67e8f@moroto.mountain/ Signed-off-by: Jacky Huang Reviewed-by: Dan Carpenter --- V3 -> V4: Move the version info lines to the correct position. V2 -> V3: Added the "Reported-by:" line. V1 -> V2: Added the "Fixes" line. drivers/tty/serial/ma35d1_serial.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/ma35d1_serial.c b/drivers/tty/serial/ma35d1_serial.c index 19f0a305cc43..3b4206e815fe 100644 --- a/drivers/tty/serial/ma35d1_serial.c +++ b/drivers/tty/serial/ma35d1_serial.c @@ -688,12 +688,13 @@ static int ma35d1serial_probe(struct platform_device *pdev) struct uart_ma35d1_port *up; int ret = 0; - if (pdev->dev.of_node) { - ret = of_alias_get_id(pdev->dev.of_node, "serial"); - if (ret < 0) { - dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n", ret); - return ret; - } + if (!pdev->dev.of_node) + return -ENODEV; + + ret = of_alias_get_id(pdev->dev.of_node, "serial"); + if (ret < 0) { + dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n", ret); + return ret; } up = &ma35d1serial_ports[ret]; up->port.line = ret;