Skip to content

Use kstrtoint_from_user() instead of parseFreq() and parse_count() to detect parse error. #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2021

Conversation

ShotaAk
Copy link
Contributor

@ShotaAk ShotaAk commented Jul 9, 2021

What does this implement/fix?

Raspberry Pi OS(debian 10.10、kernel 5.10.17)でサンプルプログラムのstep4.shを実行した際、
モータが回らないタイミングがあることを確認しました。

parseFreq()newbufのメモリを確保する際に、ゼロで初期化していないことが原因です。
メモリの確保にkzalloc()を使用し、確保したメモリにゼロをセットすることで問題が解決しました。

不具合の詳細

newbufが生成されたときに、その中身が4????のような数字で始まる場合、
かつ、
セットしたいモータ速度が-300のように先頭がマイナスの場合に問題が発生します。

指示値が-300のとき、指示値をパースした後newbuf = " 300"となるのが理想ですが、
newbuf[0]の初期値に数字が入っていると、パース後はnewbuf = "4300"となってしまいます。

その後、符号が処理されるので、最終的に-4300がモータにセットされます。
これは指示範囲外なので、モータが回りません。

Does this close any currently open issues?

いいえ

How has this been tested?

Raspberry Pi OSと、Ubuntu 20.04にて、step4.shを実行した際にモータが正常に回ることを確認してます。

Any other comments?

いいえ

Checklists

  • I have read the CONTRIBUTING guidelines.
  • I have checked to ensure there aren't other open Pull Requests for the same change.

@ShotaAk ShotaAk added the Type: Bug Bug or Bug fixes label Jul 9, 2021
@ShotaAk ShotaAk requested a review from Tiryoh July 9, 2021 07:11
@Tiryoh
Copy link
Contributor

Tiryoh commented Jul 13, 2021

char *newbuf = kmalloc(sizeof(char) * count, GFP_KERNEL);

char *newbuf = kmalloc(sizeof(char) * count, GFP_KERNEL);

上記も1文字目が-の文字列が渡される可能性があるので同様に修正が必要かと思いますがいかがでしょうか?

  • parseFreq()に限らず1文字目に-の文字列が渡される関数におけるパースエラーの修正というPRとする
  • 上記の2箇所については別PRとする

の2通りがあると思われます。

@ShotaAk
Copy link
Contributor Author

ShotaAk commented Jul 13, 2021

  • parseFreq()に限らず1文字目に-の文字列が渡される関数におけるパースエラーの修正というPRとする

このPRで他2箇所も修正します。

@Tiryoh
Copy link
Contributor

Tiryoh commented Jul 13, 2021

kstrtoint_from_user()を使うのも1つの選択肢だと思います。
関連 #55

Jetson Nano Mouseのデバイスドライバでは先行して使用していますが、いまのところこれに起因する不具合はなさそうです。
https://github.com/rt-net/JetsonNanoMouse/blob/41412bef9720f305b207b3a28490b13fa7282aea/drivers/rtmouse/rtmouse.c#L953

@ShotaAk ShotaAk force-pushed the fix_motor_control_for_raspi_os branch from 10faa7e to 7b387ae Compare July 14, 2021 07:40
@ShotaAk ShotaAk changed the title Fix parseFreq to make stable the motor control on RasPi OS. Use kstrtoint_from_user() instead of parseFreq() and parse_count() to detect parse error. Jul 15, 2021
@ShotaAk
Copy link
Contributor Author

ShotaAk commented Jul 15, 2021

kstrtoint_from_user()を使用するように修正しました。

Ubuntu 20.04 と RasPi OS (debian 10.10) 環境で、ブザー(step2sh)、モータ(step4.sh)、パルスカウンタ(step6.sh)が正常に動作することを確認しています。

@Tiryoh
Copy link
Contributor

Tiryoh commented Jul 15, 2021

以下の環境で問題が再現することを確認しました。
使用したハードウェアの構成はRaspberry Pi 4 + Raspberry Pi Mouse V3です。

# RaspberryPiMouseドライバのバージョン
$ git rev-parse --short HEAD
ea99d87
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 10 (buster)
Release:	10
Codename:	buster
$ uname -a
Linux raspberrypi 5.10.17-v7l+ #1403 SMP Mon Feb 22 11:33:35 GMT 2021 armv7l GNU/Linux

本PRの内容を適用後、以下の環境でstep2, 4, 6が動くことを確認しました。
使用したハードウェアの構成はRaspberry Pi 4 + Raspberry Pi Mouse V3です。

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 10 (buster)
Release:	10
Codename:	buster
$ uname -a
Linux raspberrypi 5.10.17-v7l+ #1403 SMP Mon Feb 22 11:33:35 GMT 2021 armv7l GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.2 LTS
Release:	20.04
Codename:	focal
$ uname -a
Linux ubuntu 5.4.0-1034-raspi #37-Ubuntu SMP PREEMPT Mon Apr 12 23:14:49 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.4 LTS
Release:	18.04
Codename:	bionic
$ uname -a
Linux ubuntu 5.3.0-1040-raspi2 #42-Ubuntu SMP Fri Apr 16 09:26:16 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux

また、-と数字以外は無視されるようになっていることを確認しました

$ echo -10 > /dev/rtcounter_r1
$ cat /dev/rtcounter_r1 
-10
$ echo -1.0 > /dev/rtcounter_r1
$ cat /dev/rtcounter_r1 
-10

@Tiryoh Tiryoh merged commit bea4d2d into master Jul 15, 2021
@Tiryoh Tiryoh deleted the fix_motor_control_for_raspi_os branch July 15, 2021 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug or Bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

parseFreqで整数形式に変換できなければエラーを返すようにする
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy