Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2808574pxb; Mon, 17 Jan 2022 06:15:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJy736s4U3AA+z7h4sPIfuCceXrt7NwPyl/PGR6lUo+D6PY2Zn96fRyt0f6XZj1ZJrSb3zDM X-Received: by 2002:a62:7c57:0:b0:4bd:fa44:95df with SMTP id x84-20020a627c57000000b004bdfa4495dfmr21050611pfc.53.1642428902783; Mon, 17 Jan 2022 06:15:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642428902; cv=none; d=google.com; s=arc-20160816; b=NYDLwAkpCY37emJAIPYlPnXamVGp6qBNUdq3UFP7vXLoM2VJQR8And4cJVgjeEtujn vej8aPV9LcbLJEmDw8tcgukbxpL5Lr5X64qQEys9RofsdYymjH4kB4jW16UnCNLlviMD v5SC12Ly2AIEedXBqCKqfzJsRmacU8tRlv/umUsF8zGr1S5i+X1Z8W1m7t2HlnkuCdTD bBW7RiKAb28gJgFeTEESs6YZIL6X3oTxNKed01mYtjWhEJoI4L1YiqamNH/Caxqx6YJs MeU8I8DM9M3xRR3Q8voTFNNAHCdgS/FoKfHLd8gngrjamLPQEtlaP3M/6cKpsZsWM49j lzpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=oYNbsridkjdw0mrmNIJXC9tA1DTH89l9mm4V1SaB7II=; b=ajaAvRf2BuEPjjSztnf6ABOllfPPUhHpzyz0qWTPswZIokP20J7L0KXd4RV34EX4qy Naan5QK+9Di/JtKXD6ioAr7ocb8MWlMZt+rwkw5cu8wyGCTFY2f9UdYHOvQFhJ0JjNs/ M3pqjzpB0Y5DjhXt6GMCXwEuUxcGhe3BYj9To8Jz379S9hlFhvDX5jKKbT4wEWtlvWRM pVaruCcwsOCkEUjQZCaixvkUt3Bb8UNjvqT68/uMely7oxqzl5/kC3SsKfL2BxnYwDSJ rKkj8vCAa5aPQDly9rpB9UpuE2pF28ODqnhEUWDxYHw5RGkrRNtBl3WxWl7fXjYnfhcF d1Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=CVzimYdj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id my15si7238201pjb.124.2022.01.17.06.14.49; Mon, 17 Jan 2022 06:15:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=CVzimYdj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234548AbiAQGC1 (ORCPT + 99 others); Mon, 17 Jan 2022 01:02:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231213AbiAQGC0 (ORCPT ); Mon, 17 Jan 2022 01:02:26 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1152C061574 for ; Sun, 16 Jan 2022 22:02:26 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id l6-20020a17090a4d4600b001b44bb75a8bso8802067pjh.3 for ; Sun, 16 Jan 2022 22:02:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :in-reply-to; bh=oYNbsridkjdw0mrmNIJXC9tA1DTH89l9mm4V1SaB7II=; b=CVzimYdjMdj+rMkORT0DnpDSFjsK5qJ9o52H6ByQvWMdtgY+ULePg/qmE2tMabdHvk NCRg/UZOcQO/IIMlQifsXFc93W0kIs5iTbcG0wbmhPl10R9FasVW2zO9MBRItg7r0iLY ereHzUwWhCM7sKdSyoLFnHkamWmG+Y1cfI/5gEdNGYK0V984ceYzWM0oz+6Mwdr7oqxA DiAwEOqTD+tyOi69Mw5guzXwCToQglXG9oG72+KBH7ltncChrRuTWUP0wPYK/eYpeo8G s9amfzOhcAIqX1+QbUhVBUBfFgxmGGk7TRFMhncrCcd/E0PX0FPgMz6P7CKPzz60Xthi q6og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:in-reply-to; bh=oYNbsridkjdw0mrmNIJXC9tA1DTH89l9mm4V1SaB7II=; b=gWb+25HBZXtLA/iw99fqXGW+oImABbJ0ZjYe6wuPKoErJaf/5h+S4IadN1Qv1LQIis psDD5eQrbbYDIBsJjNonJhUUaI12xSdwNM7hse+sdMvsGQHpx3CazsZNqJyxK8xEgJhZ kPeLLsXfFfYjwj1vaBnap/7EpOKcJ26P6QHsaEvWMu4k/PFlDaP8diXoehnfEU4r+Ffb r16Jr+aRWHpjVBXCA3eCcrp1vtfCDjFlSfBJXZdqG6fIvZXKaiPw+hkC8JMkjIEYz6UX iLr88hp9jmNmiCV3YFtJKDpiv5nBk5hUPCE0tcyxNgXHdXTr6VP2jwuxyZhB7PsAK3Uu IxHA== X-Gm-Message-State: AOAM533YjkiumV2ZaqdK00SeOEIjOy+10azuIR/1FaxMWgphMHGzyakx Jo8V7kjC78AIhihQNjYRx/4= X-Received: by 2002:a17:90b:2386:: with SMTP id mr6mr32773747pjb.24.1642399346264; Sun, 16 Jan 2022 22:02:26 -0800 (PST) Received: from mail.google.com (122-58-164-114-fibre.sparkbb.co.nz. [122.58.164.114]) by smtp.gmail.com with ESMTPSA id y3sm11160796pjp.55.2022.01.16.22.02.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jan 2022 22:02:25 -0800 (PST) Date: Mon, 17 Jan 2022 19:02:20 +1300 From: Paulo Miguel Almeida To: gregkh@linuxfoundation.org, paulo.miguel.almeida.rodenas@gmail.com, realwakka@gmail.com Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] staging: pi433: validate max bit_rate based on modulation used Message-ID: <20220117060220.GA11202@mail.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220117055849.GA10644@mail.google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Max bit rate is dependent on which modulation is used. Previous validation routine only took into consideration min bit rate which can lead a misconfiguration of the rf69 chip causing the packets not to be sent/read. This patch enhances that input check in set_bit_rate to account for modulation values and their respective max bit rate Signed-off-by: Paulo Miguel Almeida --- Meta-comments: In the patchset v1 I kept bit_rate argument's original type as I thought that changing it to accomodate values as high as 300kbps couldn't be part of this patchset and therefore it should be a separate patchset. Given that kernel test bot compilation/test process 'complained' about the argument's type, I decided to send the v2 patch that addresses the data type problem while I work on the patch that will change bit_rate type across tx_cfg and rx_cfg as this will require a bit more work. Please let me know if anyone dislikes the approach and wants me to deal with it in a different way. --- drivers/staging/pi433/rf69.c | 14 ++++++++++++-- drivers/staging/pi433/rf69.h | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c index f4ac17adcd83..adba69b8365e 100644 --- a/drivers/staging/pi433/rf69.c +++ b/drivers/staging/pi433/rf69.c @@ -223,15 +223,25 @@ int rf69_set_modulation_shaping(struct spi_device *spi, } } -int rf69_set_bit_rate(struct spi_device *spi, u16 bit_rate) +int rf69_set_bit_rate(struct spi_device *spi, u32 bit_rate) { int retval; u32 bit_rate_reg; u8 msb; u8 lsb; + enum modulation mod; + + // check if modulation is configured + mod = rf69_get_modulation(spi); + if (mod == UNDEF) { + dev_dbg(&spi->dev, "setBitRate: modulation is undefined"); + return -EINVAL; + } // check input value - if (bit_rate < 1200) { + if (bit_rate < 1200 || + (mod == FSK && bit_rate > 300000) || + (mod == OOK && bit_rate > 32768)) { dev_dbg(&spi->dev, "setBitRate: illegal input param"); return -EINVAL; } diff --git a/drivers/staging/pi433/rf69.h b/drivers/staging/pi433/rf69.h index c25942f142a6..3b8184155326 100644 --- a/drivers/staging/pi433/rf69.h +++ b/drivers/staging/pi433/rf69.h @@ -23,7 +23,7 @@ int rf69_set_data_mode(struct spi_device *spi, u8 data_mode); int rf69_set_modulation(struct spi_device *spi, enum modulation modulation); int rf69_set_modulation_shaping(struct spi_device *spi, enum mod_shaping mod_shaping); -int rf69_set_bit_rate(struct spi_device *spi, u16 bit_rate); +int rf69_set_bit_rate(struct spi_device *spi, u32 bit_rate); int rf69_set_deviation(struct spi_device *spi, u32 deviation); int rf69_set_frequency(struct spi_device *spi, u32 frequency); int rf69_enable_amplifier(struct spi_device *spi, u8 amplifier_mask); -- 2.25.4