From patchwork Tue Apr 18 17:25:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 84998 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3022645vqo; Tue, 18 Apr 2023 10:40:22 -0700 (PDT) X-Google-Smtp-Source: AKy350ZwoDfvrhg7LKJL/T5kA3FZvupE0HPa36+DDnAQUNoNoHgLl2OQ4jg5zdc6wbrkWCbPcAsz X-Received: by 2002:a17:90b:1a88:b0:247:90ea:1a7f with SMTP id ng8-20020a17090b1a8800b0024790ea1a7fmr347847pjb.37.1681839621912; Tue, 18 Apr 2023 10:40:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681839621; cv=none; d=google.com; s=arc-20160816; b=ihA+P8UYjs9yee0Ur5UVBz1W6bp+FPkT+vB1P1/cns0ByCk4mkATmRSHmqcKNW4Gzg I+TOc3GfIYarq+pOcfUr9s8LyhwMyVx8amW7UmpcntPz35T5C/xmwXQCDgVyQTopKYWC l5lCZWg4sTPjoAf9UsMKh8gg4vQ5X9wmCvQB75nX22j8bZzWjqsadFqcoC0P6pIouBsj L7fp37idN+wxEUYLkDb8ypojo8vYWQc1TTHyeZ5+IpJxrwFwbAGwnMu7zSefOF1l47N2 TGZIUCIfluIt3wwRyY5WgSqeut18ik6Tpf+OnmCjqUWIB2M2FuKdv+x7+e/QC3/Y7id4 Pv8w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=JPz8WtlEI8gh8A55a2S3L9Sb0zmAsdXhk6qjgbvuP5Y=; b=Wt4CcAWBH3LSup8KRoMrX87VAQ1sPUuBYvaqxP5cCvzCCWttu6sEMv1cZdITn16xY8 amJhuNH+ICRAkbDj94jryQg1BxX7Qam72yVwncjq7djKcwntE/HgHOecSuQBTH+P+QoW teQdm0HYgqvtFsDMpoj8he+oi6IfUGeqzdDIz4SdiNgkTPnLorOmlrm2Px0Wf8Mw3jcT EObaNUVguguVM5Wg+Z7GVA1P6VTGDAull6+gu86bGYdRrZJCFSIupAjXM3wLu25EXdI7 2mJVaWuYcKlbHkfrCbWJBv7xdZ8VLHRCwJXSggWpz4hdw6ceUEVKp+vGxktn3XDMQA5D Xq8w== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fz24-20020a17090b025800b00246cf18c353si10996868pjb.54.2023.04.18.10.40.06; Tue, 18 Apr 2023 10:40:21 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232538AbjDRR0j (ORCPT + 99 others); Tue, 18 Apr 2023 13:26:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232507AbjDRR0f (ORCPT ); Tue, 18 Apr 2023 13:26:35 -0400 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99C977EEB; Tue, 18 Apr 2023 10:26:25 -0700 (PDT) Received: by mail-ej1-f53.google.com with SMTP id fw30so22381485ejc.5; Tue, 18 Apr 2023 10:26:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681838784; x=1684430784; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JPz8WtlEI8gh8A55a2S3L9Sb0zmAsdXhk6qjgbvuP5Y=; b=SP5fFnIhkkvYn/axMr7o5RQnM1jNAkVoCoN3mZsjTqlaXS7RWMEE3HsURMO7m8O9w+ 3nm7imf7vs9zBecUeuyOc7I2SmCgeeUleW+q42aqpvQlp7sbvzl6GedOM7i0he0MEsk4 6REE0fBnSvpxkrTt70KRmzCito70Zk2coWG3GsC5REQvyC9hKdkuaUwzLr4ixcGbiBp6 X+R2GvmakOyNypsEqRhyQXym/JmKbneoHbY5vWQ0TAH8KTubH/kjN5eqaaU2VncWMooZ 32/R3kNwDoCnOVXDeXcmhaS7cIm8Yso60qrpPHK4ziTxHwv21YO0ZWUnbHaCMh1NtjYS y0KQ== X-Gm-Message-State: AAQBX9f+/bw23Z4snnQ+QWDFVwNj8vaI/RMr9xcBzD2KUAva87GHS6Y5 n0aSz6pwZoMmlJw3BcQow+8= X-Received: by 2002:a17:906:d14b:b0:93f:9b4a:12f3 with SMTP id br11-20020a170906d14b00b0093f9b4a12f3mr11979429ejb.10.1681838783990; Tue, 18 Apr 2023 10:26:23 -0700 (PDT) Received: from localhost.localdomain (aftr-62-216-205-204.dynamic.mnet-online.de. [62.216.205.204]) by smtp.googlemail.com with ESMTPSA id j23-20020a1709066c1700b0095342bfb701sm63259ejr.16.2023.04.18.10.26.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 10:26:23 -0700 (PDT) From: Johannes Thumshirn To: Wim Van Sebroeck , Guenter Roeck Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 1/2] watchdog: menz069_wdt: fix watchdog initialisation Date: Tue, 18 Apr 2023 19:25:30 +0200 Message-Id: <20230418172531.177349-2-jth@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230418172531.177349-1-jth@kernel.org> References: <20230418172531.177349-1-jth@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763536663403656946?= X-GMAIL-MSGID: =?utf-8?q?1763536663403656946?= Doing a 'cat /dev/watchdog0' with menz069_wdt as watchdog0 will result in a NULL pointer dereference. This happens because we're passing the wrong pointer to watchdog_register_device(). Fix this by getting rid of the static watchdog_device structure and use the one embedded into the driver's per-instance private data. Signed-off-by: Johannes Thumshirn Reviewed-by: Guenter Roeck --- drivers/watchdog/menz69_wdt.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/watchdog/menz69_wdt.c b/drivers/watchdog/menz69_wdt.c index 8973f98bc6a5..bca0938f3429 100644 --- a/drivers/watchdog/menz69_wdt.c +++ b/drivers/watchdog/menz69_wdt.c @@ -98,14 +98,6 @@ static const struct watchdog_ops men_z069_ops = { .set_timeout = men_z069_wdt_set_timeout, }; -static struct watchdog_device men_z069_wdt = { - .info = &men_z069_info, - .ops = &men_z069_ops, - .timeout = MEN_Z069_DEFAULT_TIMEOUT, - .min_timeout = 1, - .max_timeout = MEN_Z069_WDT_COUNTER_MAX / MEN_Z069_TIMER_FREQ, -}; - static int men_z069_probe(struct mcb_device *dev, const struct mcb_device_id *id) { @@ -125,15 +117,19 @@ static int men_z069_probe(struct mcb_device *dev, goto release_mem; drv->mem = mem; + drv->wdt.info = &men_z069_info; + drv->wdt.ops = &men_z069_ops; + drv->wdt.timeout = MEN_Z069_DEFAULT_TIMEOUT; + drv->wdt.min_timeout = 1; + drv->wdt.max_timeout = MEN_Z069_WDT_COUNTER_MAX / MEN_Z069_TIMER_FREQ; - drv->wdt = men_z069_wdt; watchdog_init_timeout(&drv->wdt, 0, &dev->dev); watchdog_set_nowayout(&drv->wdt, nowayout); watchdog_set_drvdata(&drv->wdt, drv); drv->wdt.parent = &dev->dev; mcb_set_drvdata(dev, drv); - return watchdog_register_device(&men_z069_wdt); + return watchdog_register_device(&drv->wdt); release_mem: mcb_release_mem(mem); From patchwork Tue Apr 18 17:25:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 84986 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3017261vqo; Tue, 18 Apr 2023 10:30:36 -0700 (PDT) X-Google-Smtp-Source: AKy350Y3vIVgmD6bV8hqGGiz/k9ec3lw3d6IeA9n2mxndOo5A4bQZLEG1udXq43bKEL6VFJdIG8h X-Received: by 2002:a17:90b:230b:b0:23d:3931:7b49 with SMTP id mt11-20020a17090b230b00b0023d39317b49mr345824pjb.35.1681839035694; Tue, 18 Apr 2023 10:30:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681839035; cv=none; d=google.com; s=arc-20160816; b=ZAjDF0Srzvc6ny4dIVvu5ItC0gaatkQyMv8v8uolYSSyAwZTOO8Y//3cxX49ZJcc/S N+dXkJSNx1MBwd2orX2HWzkB1oLYiRRPocWTSibmxv8bqO/zGySwB4kw7/PJk3KQWIka L9KClxTT1H+XNbBr7f2GpuPAWhGXDe21/xeHvmyiK6XflrtUwINWTq0QIhNVoRKRW1Rq 9UQiiwuJmufX3Q49r6IE/Ak9duDLQ05Onxqq8E7RnlIHXrW7QtfzRKJhorL0MpvrmEbp OIAPmjSOV+roLIuGouo/1QvVc0w84Ka8Oa3Ro/8tifavUw6oWeR57sUyjkbI7ndw75v3 WYeg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Y75P8H32UG8qaN1RFcrKVl4lR71O6GrEWubbNzGhkQE=; b=w027iGQTMSAqVBSCbkc583SWNeMmcDA4Dvu37DKeH0wAYwWV2kXJ0wKqgpSYW0Lm+9 D+SRsDXckxmQIb+QX/joxjMdYAZLYyPmlGSCe8pdiwCEwwpLbc+T2VEwceCIADdAkBGp 93lrV3CRJ6TVdYPrZM5svHHoMDcJP7Ov7Xq1oA5Q8aNFBdpOI2Maze8Xe5LNtC4Vu4JA IW0s+ndVOswp1XWm9ioXCG88gam/LqTfyiL4NBBpkJ5CGVXy+5/yCb+vqW68FjIJajAp JvU/IDOeq1GzePWkWX9c/ekzxokvV3IRSYT3kcnUuhU8rjmNEyOngA+pHOa4x3sha356 5lpg== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j70-20020a638b49000000b0051b6e9c38f8si11781731pge.335.2023.04.18.10.30.20; Tue, 18 Apr 2023 10:30:35 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232539AbjDRR0l (ORCPT + 99 others); Tue, 18 Apr 2023 13:26:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232513AbjDRR0i (ORCPT ); Tue, 18 Apr 2023 13:26:38 -0400 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34555BB92; Tue, 18 Apr 2023 10:26:29 -0700 (PDT) Received: by mail-ej1-f50.google.com with SMTP id xd13so41241798ejb.4; Tue, 18 Apr 2023 10:26:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681838787; x=1684430787; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y75P8H32UG8qaN1RFcrKVl4lR71O6GrEWubbNzGhkQE=; b=Z1XH00UTWa5NBh071ecnWf7eosd+V24Jyz0Z4ZGz0XoJA2UJGfVO8c3xky7R74z/gY Hl2omgF/LsvsAp7jDGAuBP5Vb8BlGCkJLymxYJyo0KZrvZt1pfltq3GZA1RlAcFg/vSj mXUp6n2jAGg4QKlunTYfIycM1yfkbu/eFge1Q/zlrLhck02TkcFUqxntQffF0Csm/2f8 VfP5NUJMpDtdlt0hvHy1E3EHP45HDDd6NfAknQ8TROsj53fz97u9nia5N0hMETQZWY11 CybX4L5+11mtzvQgJcIqOV42A/5ifnHaGEoSmXdI4hN/mIP1F6QJAPniEz9oVZkZVmM9 F/Cg== X-Gm-Message-State: AAQBX9ffELxSTBUVU8RwaCgVtSbnn/+7uBJScdx89+CfHmxbqojK9w1r cGzc98j8dGq4Yk6vETXVoHr/Hn+XIHPINQ== X-Received: by 2002:a17:907:3c23:b0:94a:7da2:d339 with SMTP id gh35-20020a1709073c2300b0094a7da2d339mr9252149ejc.26.1681838784884; Tue, 18 Apr 2023 10:26:24 -0700 (PDT) Received: from localhost.localdomain (aftr-62-216-205-204.dynamic.mnet-online.de. [62.216.205.204]) by smtp.googlemail.com with ESMTPSA id j23-20020a1709066c1700b0095342bfb701sm63259ejr.16.2023.04.18.10.26.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 10:26:24 -0700 (PDT) From: Johannes Thumshirn To: Wim Van Sebroeck , Guenter Roeck Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn Subject: [PATCH 2/2] watchdog: menz069_wdt: fix timeout setting Date: Tue, 18 Apr 2023 19:25:31 +0200 Message-Id: <20230418172531.177349-3-jth@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230418172531.177349-1-jth@kernel.org> References: <20230418172531.177349-1-jth@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763536048758880230?= X-GMAIL-MSGID: =?utf-8?q?1763536048758880230?= When setting the timeout for the menz069_wdt watchdog driver, we erroneously read from the 'watchdog value register' (WVR) instead of the 'watchdog timer register' (WTR) and then write the value back into WTR. This can potentially lead to wrong timeouts and wrong enable bit settings. Signed-off-by: Johannes Thumshirn Reviewed-by: Guenter Roeck --- drivers/watchdog/menz69_wdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/watchdog/menz69_wdt.c b/drivers/watchdog/menz69_wdt.c index bca0938f3429..3c98030b9fcd 100644 --- a/drivers/watchdog/menz69_wdt.c +++ b/drivers/watchdog/menz69_wdt.c @@ -77,7 +77,7 @@ static int men_z069_wdt_set_timeout(struct watchdog_device *wdt, wdt->timeout = timeout; val = timeout * MEN_Z069_TIMER_FREQ; - reg = readw(drv->base + MEN_Z069_WVR); + reg = readw(drv->base + MEN_Z069_WTR); ena = reg & MEN_Z069_WTR_WDEN; reg = ena | val; writew(reg, drv->base + MEN_Z069_WTR);