You have used the wrong verb -- "painted." Please check to see which word you really want.
3 is correct. You don't need any commas in that sentence.
1. He painted food for hungry people.
2. He painted food for the hungry.
(Are both the same?)
3. In China, there lived a poor boy who loved to paint(,) and whose name was Ma Liang.
(Is this sentence grammatical? Do we have to use 'comma' before 'and' or not?)
3 answers
With a magic paintbrush, he painted food. (folktale)
Ohh. OK.
Both of those sentences are correct, then.
Both of those sentences are correct, then.