Skip to content
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

Mpu6050 device improvement and cdev usage #33

Open
wants to merge 14 commits into
base: Sergii.Romantsov
Choose a base branch
from

Conversation

sergiiromantsov
Copy link

@sergiiromantsov sergiiromantsov commented Nov 19, 2017

Properly rebased pull-request #29 (up to commit d2f5920).
Improved mpu6050 implementation.
Added storage for 10 latest reads from mpu6050.
Added cdevs to print data in one-line and ten-lines format.
Added timer to read data each 1000 msecs.

@an1kh
Copy link
Contributor

an1kh commented Nov 21, 2017

I have a question: what was the reason for using sysfs kobject?

Also have several warnings about format:

  • avoid using characters like minuses in commit messages, they may be treated as diff info.
  • change the author completely or add a second line, don't modify the original one.
  • avoid using c++ comments (use c-style /* */), gcc-style struct declarations (use c99: .xyz = 123; ).

@sergiiromantsov
Copy link
Author

<<< I have a question: what was the reason for using sysfs kobject?
To be allowed to use sysfs_create_files
<<< avoid using characters like minuses in commit messages, they may be treated as diff info.
ok

Copy link
Contributor

@an1kh an1kh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix checkpatch errors (and warnings if possible). e.g:

../../linux/scripts/checkpatch.pl -f *.c
../../linux/scripts/checkpatch.pl -f *.h

Code itself is OK. Please fix format issues and I will have no objections.

@sergiiromantsov
Copy link
Author

CS is done
Another PRs will be able to fix after 25 December

@an1kh
Copy link
Contributor

an1kh commented Dec 13, 2017

Thank you! Please merge

Copy link
Collaborator

@AleksandrBulyshchenko AleksandrBulyshchenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made shallow review and haven't tested the solution.

Generally I like the work, which you've done. 👍
The driver looks good despite of unneeded complexity in some parts.

I've commented inline some issues.

And here are some more general notes:

  • Implementation of mpu6050_data module looks like example of overengineering for this case:
    • If you want to create generic collection, it shouldn't use mpu6050-specific types;
    • If its the only purpose to store 10 samples from the mpu6050 - it might be much simpler;
  • Please use conventional form of tagging commit subjects (mpu6050: ... in this case);
  • Also commit messages may be more descriptive;
  • And don't forget SOB line;
  • 7c095fa ("[Lesson 6] mpu6050 review fix") is empty commit;

IMO at least commit messages and some obvious issues should be fixed before merging.

struct mpu6050_data_list *element_iter_current;
struct mpu6050_data_list list;
};

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, never ever do like that.
Functions (except inline) mustn’t be defined in header files!

INDEX_GYRO_Z,
INDEX_TEMPERATURE,
INDEX_COUNT,
/* Another level of data*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid mixing indexes of different arrays within the same enum.
The following are not for the data - they are for extra_data and enum should be named accordingly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


struct cdevs_holder *get_cdevs(void)
{
static struct cdevs_holder g_cdevs_holder;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the driver's static data defined as local variable?
It may have some sense for future compatibility if you're going to expand the driver to support several instances.
But AFAIK this is not the case.
Right now it makes driver understanding and debugging harder with no benefit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if (result < 0)
goto error1;
cdevs->cdev_full.major = MAJOR(cdevs->cdev_full.dev_no);
cdevs->cdev_line.read_all = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like copy-paste error is here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

struct cdev_instance {
unsigned int major;
dev_t dev_no;
dev_t read_all;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type of read_all seems to be wrong.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

g_reading_thread = kthread_run(reading_thread, NULL, "mpu6050_read_th");
if (!g_reading_thread) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong error handling - kthread_run will return negative code in case of errors.
IS_ERR macro should be used for verification.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


if (g_reading_thread) {
complete(&g_read_comletion);
kthread_stop(g_reading_thread);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to set should_stop flag by kthread_stop before waking up the thread by complete.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

kthread_stop(g_reading_thread);
}
result = del_timer_sync(&g_read_timer);
pr_info("mpu6050: timer deleted %d\n", result);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logically timer should be stopped before deleting the thread.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

NULL,
};

/* Gets a number of attributes + 1 (null-terminated) */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In current implementation there's no need in attributes_count() function.
So why not to simplify code a bit?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/* functionality */
static size_t get_attribute_index(struct kobj_attribute const *attribute);

static int mpu6050_read_data(bool debug)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely wrong way of controlling debug printout.
It should be done on preprocessing stage.
Consider defining macro wrapper over dev_info, which will be expanded to nothing if debug mode not defined.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is over-control. It used to allow do not print for any type: or debug, or release

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming the argument to print_out doesn't change anything.
The value provided to it is hardcodded, so there's no sense to keep it as parameter - define should be used instead.

Instead of sysfs class used sysfs kobject.
Files-data created at once.
Reading of data is done by one function.
Controlled resources on initialization failure.
Added functionality to hold 10 last reads of data from mpu6050 device.
Data from device mpu6050 will be read not often than 1 time per second.
Fixed misprint in storing timestamp: it was possibility to
store diff of timestamps instead of real value.
Added charetcer-device that allows to read mpu6050-device data in
one-line format.
Implementation from header-files (mpu6050_cdev.h, mpu6050_data.h) is moved to source-files.
File with initialization-functions wasn't compiled.
Avoided usage of c++-style comments.
Added author.
Added support to dump latest 10 reads from mpu6050 by charecter device.
Structure of data and access to them are incapsulated to allow exclusive access and synchronization.
Added synchronization for data reading/writing.
Timer is added to read data each 1000 msecs.
Code correction according to checkpatch.pl
Cleaned code: avoided unused functions.
Added support to read to user buffer with requested size.
Corrected misprints for variable types.
Divided indexes for different data.
Improved module unitialization.
Copy link
Collaborator

@AleksandrBulyshchenko AleksandrBulyshchenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants