The Tana Kama and R' Shimon Ben Gamliel argue whether a father is allowed to take away his inheritance from his sons who would be inheriting him, when his motivation for doing say is that they aren't behaving properly. The conclusion of the gemara is that the tana kama holds that this is forbidden, and the rashbam points out that we pasken like the Rabbonon, against rsb"g.
However, it is unclear from the gemara if this halacha only applies when there are sons who should be inheriting, but not to other inheritors, or would it even apply to taking away the inheritance from whoever is in line to inherit? The question can be broken down into 2 parts. Is there a violation to take away from daughters when there are no sons? Even if there is a violation to take away from all his offspring even daughters, perhaps it would not apply when his father or brother are the inheritors?
The Aruch Hashulchan (282) raises the question. He points out that the gemara seems to imply that it is specifically a din when there are sons who should be inheriting. However, the Rambam uses the term "inheritors" implying that it would apply to all inheritors. He concludes by compromising. One should not remove ALL the inheritance from any inheritor, but as long as he is leaving some behind he is allowed to give some to others as well. However, when he has sons he is not allowed to take away any of the inheritance to give to someone else, but is allowed to give what he wants to tzedaka - דזהו ודאי שראוי לעשיר לעשות כן וכן מנהג העולם. But, the primary bulk of the estate should be given to his children.
The Chasam Sofer (cited in pischei teshuva 282) holds that the gemara which says that inheritance shouldn't be manipulated isn't limited to sons but applies to all relatives. Also, even if he is going to be doing a mitzvah such as tzedaka with the money, it shouldn't be taken away from any relative who would be inheriting. Furthermore, even if he is not going to be giving it all, just some of it to tzedaka, he shouldn't do that.
On the other hand, the Tashbetz holds that the severe violation is only if he takes away from sons and leaves nothing behind, but even for other inheritors and even if he leaves something behind the ruach of chachamim isn't content with him. BUT, if he doesn't have children then he should use the money for a mitzvah even though he will be taking away from the inheritors. The rationale is that when he doesn't leave sons he needs a zechus to be saved from geihenom and he has a right to protect himself before other relatives.
The Tashbetz also suggests that these restrictions may apply only to a person who is giving a gift of a shechiv mei'rah where the gift goes into effect only with his death. But if he gives a regular gift in his lifetime, he can do whatever he chooses. Although the gemara in kesubos seems to hold that the issur would apply even to a regular gift, so long as he leaves his children with a significant portion it is permitted.